diff --git a/src/main/jastadd/Analysis.jrag b/src/main/jastadd/Analysis.jrag index 89d6fb0385ce39f2a3bd0d46671672e0ce0d7d4c..27f3a7d89731f351b8a21043e9b2a816cd3d3548 100644 --- a/src/main/jastadd/Analysis.jrag +++ b/src/main/jastadd/Analysis.jrag @@ -76,26 +76,30 @@ aspect ComponentAnalysis { return null; } - /* Should this better return the component, where it is defined previously defined? */ //--- isInvalidRedefinition --- /** * Check, if a component with the same name is already declared in some supertype */ - syn boolean Component.isInvalidRedefinition() = false; - eq TokenComponent.isInvalidRedefinition() = hasInvalidRedefinitionOn(enclosingTypeDecl()); - eq RelationComponent.isInvalidRedefinition() = hasInvalidRedefinitionOn(getTypeUse().decl()); + syn boolean Component.isInvalidRedefinition() = invalidRedefinition() != null; - syn boolean Component.hasInvalidRedefinitionOn(TypeDecl td) { - if (td == null) return false; + /** + * Check, if a component with the same name is already declared in some supertype, and return it, if any + */ + syn Component Component.invalidRedefinition() = null; + eq TokenComponent.invalidRedefinition() = invalidRedefinitionOn(enclosingTypeDecl()); + eq RelationComponent.invalidRedefinition() = invalidRedefinitionOn(getTypeUse().decl()); + + syn Component Component.invalidRedefinitionOn(TypeDecl td) { + if (td == null) return null; while (td.hasSuper() && td.getSuper().decl() != null) { td = td.getSuper().decl(); // find a matching component on the RHS of the (current) super type Component c = findComponent(td, getID()); - if (c != null && !this.isEqual(c)) return true; + if (c != null && !this.isEqual(c)) return c; } - return false; + return null; } //--- isEqual --- diff --git a/src/main/jastadd/Errors.jrag b/src/main/jastadd/Errors.jrag index 0ff888ac1fa2bd4e3bb68cf1bb147a44aae46dbe..b1ec073575e4ea6c15e924c1f6c6b95eeaba2cba 100644 --- a/src/main/jastadd/Errors.jrag +++ b/src/main/jastadd/Errors.jrag @@ -21,12 +21,14 @@ aspect Errors { to Program.errors(); RelationComponent contributes error("Role '" + name() - + "' is an invalid redefinition for type '" + getTypeUse().decl() + "'") + + "' is an invalid redefinition for type '" + getTypeUse().decl() + "', conflicts with supertype '" + + invalidRedefinition().enclosingTypeDecl() + "'") when isInvalidRedefinition() to Program.errors(); TokenComponent contributes error("Token '" + name() - + "' is an invalid redefinition for type '" + enclosingTypeDecl() + "'") + + "' is an invalid redefinition for type '" + enclosingTypeDecl() + "', conflicts with supertype '" + + invalidRedefinition().enclosingTypeDecl() + "'") when isInvalidRedefinition() to Program.errors(); diff --git a/src/test/jastadd/errors/Inheritance.expected b/src/test/jastadd/errors/Inheritance.expected index 3742ef5f58acd607b8bef9d62bd911c8fe540a22..b3382e004ae6e15ca9bbd1ed6695ece0e3110fbe 100644 --- a/src/test/jastadd/errors/Inheritance.expected +++ b/src/test/jastadd/errors/Inheritance.expected @@ -1,3 +1,3 @@ Errors: -$FILENAME Line 4, column 12: Token 'X' is an invalid redefinition for type 'B3' -$FILENAME Line 7, column 5: Role 'X' is an invalid redefinition for type 'B2' +$FILENAME Line 4, column 12: Token 'X' is an invalid redefinition for type 'B3', conflicts with supertype 'A' +$FILENAME Line 7, column 5: Role 'X' is an invalid redefinition for type 'B2', conflicts with supertype 'A' diff --git a/src/test/jastadd/errors/InheritanceLeft.expected b/src/test/jastadd/errors/InheritanceLeft.expected index e94e4efa2081b32caa399de600dec37d5a6dfe20..a897e473946be908e3cac5f6b6d59628720d3376 100644 --- a/src/test/jastadd/errors/InheritanceLeft.expected +++ b/src/test/jastadd/errors/InheritanceLeft.expected @@ -1,3 +1,3 @@ Errors: -$FILENAME Line 4, column 12: Token 'X' is an invalid redefinition for type 'B3' -$FILENAME Line 7, column 10: Role 'X' is an invalid redefinition for type 'B2' +$FILENAME Line 4, column 12: Token 'X' is an invalid redefinition for type 'B3', conflicts with supertype 'A' +$FILENAME Line 7, column 10: Role 'X' is an invalid redefinition for type 'B2', conflicts with supertype 'A'