Commit 15434aa2 authored by René Schöne's avatar René Schöne
Browse files

Add conflicting type for invalid redefinition errors.

parent 5fbb5a86
Pipeline #4662 passed with stage
in 2 minutes and 9 seconds
......@@ -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 ---
......
......@@ -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();
......
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'
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'
Markdown is supported
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