Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typechecker does not throw error on constructor without arguments #2120

Open
toinehartman opened this issue Jan 14, 2025 · 3 comments
Open
Assignees

Comments

@toinehartman
Copy link
Contributor

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.

@jurgenvinju
Copy link
Member

jurgenvinju commented Jan 14, 2025

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
Copy link
Member

Lines 127 and 132 seem to have similar issues.

@jurgenvinju
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants