Skip to content

Commit

Permalink
Merge pull request #2147 from lf-lang/fix-duplicate-attrparm
Browse files Browse the repository at this point in the history
Fix for #2087
lhstrh authored Jan 25, 2024
2 parents b9e4795 + df85bbf commit 3177bc1
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<EClass, Map<QualifiedName, IEObjectDescription>> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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 {

0 comments on commit 3177bc1

Please sign in to comment.