diff --git a/spec/jastadd/Analysis.jrag b/spec/jastadd/Analysis.jrag index 223a1fbebd5674c09da1fe4c3fa644d8322b0bf6..6ee9e64e929594c81ad01ac5fb8fb6ba7fa919ae 100644 --- a/spec/jastadd/Analysis.jrag +++ b/spec/jastadd/Analysis.jrag @@ -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) { - for (Component c: td.getComponents()) { - if (c.name().equals(name)) { - return c; - } + 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; } diff --git a/tests/errors/Inheritance.expected b/tests/errors/Inheritance.expected new file mode 100644 index 0000000000000000000000000000000000000000..42aab57d7f2ea21c0440ff60a46e30191482c7de --- /dev/null +++ b/tests/errors/Inheritance.expected @@ -0,0 +1,3 @@ +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' diff --git a/tests/errors/Inheritance.relast b/tests/errors/Inheritance.relast new file mode 100644 index 0000000000000000000000000000000000000000..9f012a95b93d32a27ab21661f0b354ae1374b0c1 --- /dev/null +++ b/tests/errors/Inheritance.relast @@ -0,0 +1,6 @@ +A ::= X; +B1 : A ::= X; +B2 : A; +X; + +rel B2.X -> X; diff --git a/tests/errors/Makefile b/tests/errors/Makefile index 75b5ba0c224beffe7c5952ccac8ee88359dfc8dd..6d94e59bd53b0644b322486fcfd7078d167483d6 100644 --- a/tests/errors/Makefile +++ b/tests/errors/Makefile @@ -4,4 +4,11 @@ build-jar: (cd ../../ && ant jar) test: java -jar ../../relast-compiler.jar Errors.relast 2> Errors.out || true - diff Errors.out Errors.expected \ No newline at end of file + 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 diff --git a/tests/valid/Makefile b/tests/valid/Makefile index a18b8217c5d12b9783c31e2b6aebbea11f1d7aff..786fe1fd91cd599633b5503896141987092ddee3 100644 --- a/tests/valid/Makefile +++ b/tests/valid/Makefile @@ -1,5 +1,8 @@ all: build-jar test test: compile run check-idempotent + @echo "#" + @echo "# VALID TESTS OK" + @echo "#" build-jar: (cd ../../ && ant jar) diff --git a/tests/valid/Test.java b/tests/valid/Test.java index a40c246ddbe02c195346001a70afe6d187eb44e8..c2f06653bd744944699554d508dfd2eccb1c6086 100644 --- a/tests/valid/Test.java +++ b/tests/valid/Test.java @@ -30,8 +30,6 @@ public class Test { testBi9(); testImmutableList(); - - System.out.println("TESTS OK"); } /**