Skip to content
Snippets Groups Projects
Commit 2834ef70 authored by Niklas Fors's avatar Niklas Fors
Browse files

Include supertype when checking for name duplicates

parent 549c19c0
No related branches found
No related tags found
No related merge requests found
...@@ -44,22 +44,31 @@ aspect ComponentAnalysis { ...@@ -44,22 +44,31 @@ aspect ComponentAnalysis {
syn boolean Component.isAlreadyDeclared() syn boolean Component.isAlreadyDeclared()
= !isTargetOfDirectedRelation() = !isTargetOfDirectedRelation()
&& toTypeDecl() != null
&& lookupComponent(toTypeDecl(), name()) != this; && lookupComponent(toTypeDecl(), name()) != this;
inh Component Component.lookupComponent(TypeDecl td, String name); inh Component Component.lookupComponent(TypeDecl td, String name);
eq Program.getChild().lookupComponent(TypeDecl td, String name) { eq Program.getChild().lookupComponent(TypeDecl td, String name)
if (td != null) { = lookupComponentSyn(td, name);
for (Component c: td.getComponents()) { syn Component Program.lookupComponentSyn(TypeDecl td, String name) {
if (c.name().equals(name)) { // Check super type first to find duplicates (shadowing is not allowed)
return c; if (td.hasSuper() && td.getSuper().decl() != null) {
} Component c = lookupComponentSyn(td.getSuper().decl(), name);
if (c != null) return c;
}
for (Component c: td.getComponents()) {
if (c.name().equals(name)) {
return c;
} }
} }
for (Relation r: getRelations()) { for (Relation r: getRelations()) {
Component c = r.getLeft().lookup(td, name); Component c = r.getLeft().lookup(td, name);
if (c != null) return c; if (c != null) return c;
c = r.getRight().lookup(td, name); c = r.getRight().lookup(td, name);
if (c != null) return c; if (c != null) return c;
} }
return null; return null;
} }
......
Errors:
Line 2, column 12: Component 'X' is already declared for type 'B1'
Line 6, column 5: Component 'X' is already declared for type 'B2'
A ::= X;
B1 : A ::= X;
B2 : A;
X;
rel B2.X -> X;
...@@ -4,4 +4,11 @@ build-jar: ...@@ -4,4 +4,11 @@ build-jar:
(cd ../../ && ant jar) (cd ../../ && ant jar)
test: test:
java -jar ../../relast-compiler.jar Errors.relast 2> Errors.out || true java -jar ../../relast-compiler.jar Errors.relast 2> Errors.out || true
diff Errors.out Errors.expected diff Errors.out Errors.expected
\ No newline at end of file
java -jar ../../relast-compiler.jar Inheritance.relast 2> Inheritance.out || true
diff Inheritance.out Inheritance.expected
@echo "#"
@echo "# ERROR TESTS OK"
@echo "#"
\ No newline at end of file
all: build-jar test all: build-jar test
test: compile run check-idempotent test: compile run check-idempotent
@echo "#"
@echo "# VALID TESTS OK"
@echo "#"
build-jar: build-jar:
(cd ../../ && ant jar) (cd ../../ && ant jar)
......
...@@ -30,8 +30,6 @@ public class Test { ...@@ -30,8 +30,6 @@ public class Test {
testBi9(); testBi9();
testImmutableList(); testImmutableList();
System.out.println("TESTS OK");
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment