From 2665f114bc34cb583a8c2f82f94ce8f638898d3e Mon Sep 17 00:00:00 2001 From: Alexander Schulz-Rosengarten Date: Wed, 10 Jan 2024 14:56:03 +0100 Subject: [PATCH 1/2] Fixed incorrect detection of duplicate IDs in attribute parameters --- .../LFNamesAreUniqueValidationHelper.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java b/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java index 9c6267cb0a..6694a642c1 100644 --- a/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java +++ b/core/src/main/java/org/lflang/validation/LFNamesAreUniqueValidationHelper.java @@ -1,7 +1,13 @@ package org.lflang.validation; +import java.util.Map; import org.eclipse.emf.ecore.EClass; +import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.resource.IEObjectDescription; import org.eclipse.xtext.validation.NamesAreUniqueValidationHelper; +import org.eclipse.xtext.validation.ValidationMessageAcceptor; +import org.lflang.lf.AttrParm; +import org.lflang.lf.Attribute; import org.lflang.lf.LfPackage; public class LFNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHelper { @@ -22,4 +28,32 @@ public EClass getAssociatedClusterType(EClass eClass) { } return super.getAssociatedClusterType(eClass); } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("deprecation") + protected void checkDescriptionForDuplicatedName( + IEObjectDescription description, + Map> clusterTypeToName, + ValidationMessageAcceptor acceptor) { + // Special handling for value id in AttrParm + if (description.getEClass() == LfPackage.eINSTANCE.getAttrParm()) { + var param = (AttrParm) description.getEObjectOrProxy(); + var clusterType = getAssociatedClusterType(param.eClass()); + if (param.eContainer() instanceof Attribute attribute) { + // Only check for duplicates in the same attribute + for (int i = 0; i < attribute.getAttrParms().indexOf(param); i++) { + var prev = attribute.getAttrParms().get(i); + if (param.getName() == null + ? param.getName() == prev.getName() + : param.getName().equals(prev.getName())) { + createDuplicateNameError(description, clusterType, acceptor); + return; + } + } + } + } else { + super.checkDescriptionForDuplicatedName(description, clusterTypeToName, acceptor); + } + } } From df85bbf041bfaade7c6ddbc06639df24b000c087 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 24 Jan 2024 15:45:28 -0800 Subject: [PATCH 2/2] Add test --- .../compiler/LinguaFrancaValidationTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index 2d95e0ac4a..11fff6c2c9 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -108,6 +108,29 @@ private Model parseWithError(String s) throws Exception { return model; } + /** Assert no issues when multiple labels are used. */ + @Test + public void multipleLabels() throws Exception { + String testCase = + """ + target C + reactor Source { + output out: int + timer t(1 nsec, 10 msec) + state s: int = 0 + + @label(value="Foo") + reaction(startup) {= lf_print("Starting Source"); =} + + @label(value="Bar") + reaction(t) -> out {= + lf_set(out, self->s++); + lf_print("Inside source reaction_0"); + =} + }"""; + validator.assertNoIssues(parseWithoutError(testCase)); + } + /** Ensure that duplicate identifiers for actions reported. */ @Test public void tracingOptionsCpp() throws Exception {