rascal
rascal copied to clipboard
Typechecker does not throw error on constructor without arguments
Describe the bug
The typechecker does not show errors when passing a constructor where a value of the type of the ADT would be expected.
To Reproduce
data A = a(int i);
void m(void(A) x) {
void y(A _) { ; }
x(a); // expect error
x(a(1));
y(a); // expect error
y(a(1));
}
Expected behavior
Errors on the first calls of x and y, that A::a(int i) is not of type A.
This seems to be the cause
https://github.com/usethesource/rascal-core/blob/21e6b8d1622b620ae3fc53154643fc0cb1b74033/src/org/rascalmpl/core/library/lang/rascalcore/check/AType.rsc#L124
Those two lines confuse the constructor function for the constructor node instance.
Lines 127 and 132 seem to have similar issues.
This has another minor issue here: https://github.com/usethesource/rascal-core/blob/21e6b8d1622b620ae3fc53154643fc0cb1b74033/src/org/rascalmpl/core/library/lang/rascalcore/check/AType.rsc#L125
The return type does not have to be equal for a constructor function type to be a subtype of a functiontype. The adt type should be a subtype of the function return type.
Thanks @toinehartman for this clear repo case and thanks @jurgenvinju for pointing in the right direction of the cause of this. Fixed and test added.