Commit 2834ef70 authored by Niklas Fors's avatar Niklas Fors
Browse files

Include supertype when checking for name duplicates

parent 549c19c0
......@@ -44,22 +44,31 @@ aspect ComponentAnalysis {
syn boolean Component.isAlreadyDeclared()
= !isTargetOfDirectedRelation()
&& toTypeDecl() != null
&& lookupComponent(toTypeDecl(), name()) != this;
inh Component Component.lookupComponent(TypeDecl td, String name);
eq Program.getChild().lookupComponent(TypeDecl td, String name) {
if (td != null) {
eq Program.getChild().lookupComponent(TypeDecl td, String name)
= lookupComponentSyn(td, name);
syn Component Program.lookupComponentSyn(TypeDecl td, String name) {
// Check super type first to find duplicates (shadowing is not allowed)
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()) {
Component c = r.getLeft().lookup(td, name);
if (c != null) return c;
c = r.getRight().lookup(td, name);
if (c != null) return c;
}
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;
......@@ -5,3 +5,10 @@ build-jar:
test:
java -jar ../../relast-compiler.jar Errors.relast 2> Errors.out || true
diff Errors.out Errors.expected
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
test: compile run check-idempotent
@echo "#"
@echo "# VALID TESTS OK"
@echo "#"
build-jar:
(cd ../../ && ant jar)
......
......@@ -30,8 +30,6 @@ public class Test {
testBi9();
testImmutableList();
System.out.println("TESTS OK");
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment