rascal icon indicating copy to clipboard operation
rascal copied to clipboard

Typechecker does not throw error on constructor without arguments

Open toinehartman opened this issue 10 months ago • 3 comments

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.

toinehartman avatar Jan 14 '25 11:01 toinehartman

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.

jurgenvinju avatar Jan 14 '25 12:01 jurgenvinju

Lines 127 and 132 seem to have similar issues.

jurgenvinju avatar Jan 14 '25 12:01 jurgenvinju

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.

jurgenvinju avatar Jan 14 '25 12:01 jurgenvinju

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.

PaulKlint avatar Jul 27 '25 19:07 PaulKlint