Describe the bug
There are inconsistencies in how the typechecker and interpreter handle redeclaration of common keyword fields in ADTs as non-common keyword fields.
To Reproduce
Typechecker:
data Foo = foo(int x = 1, int x = 5); // Error: "Double declaration of field `x`"
data Bar(int x = 1) = bar(int x = 5); // No error
data Baz(int x = 1) = baz(str x = ""); // No error
Interpreter:
rascal>data Foo = foo(int x = 1, int x = 5);
ok
rascal>foo().x
int: 5
rascal>data Bar(int x = 1) = bar(int x = 5);
ok
rascal>bar().x
int: 1
rascal>data Baz(int x = 1) = baz(str x = "");
io.usethesource.vallang.exceptions.RedeclaredKeywordParameterException: Keyword parameter x was declared earlier as int
Expected behavior
In general, after discussing it with @DavyLandman and @rodinaarssen, I would expect the following rules:
- Redeclaring a non-common keyword field as a non-common keyword field is forbidden.
- Redeclaring a common keyword field as a non-common keyword field with the same type is allowed (to change the default).
- Redeclaring a common keyword field as a non-common keyword field with a different type is forbidden.
Applied to the examples above:
- The compiler and interpreter should report errors for
Foo. The interpreter doesn't do this yet.
- The compiler and interpreter should not report errors for
Bar, and the defalut should be 5. The interpreter doesn't do this yet.
- The compiler and interpreter should report errors for
Baz. The typechecker doesn't do this yet.
Describe the bug
There are inconsistencies in how the typechecker and interpreter handle redeclaration of common keyword fields in ADTs as non-common keyword fields.
To Reproduce
Typechecker:
Interpreter:
Expected behavior
In general, after discussing it with @DavyLandman and @rodinaarssen, I would expect the following rules:
Applied to the examples above:
Foo. The interpreter doesn't do this yet.Bar, and the defalut should be5. The interpreter doesn't do this yet.Baz. The typechecker doesn't do this yet.