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

NPE while running function from constructor keyword argument #2121

Open
toinehartman opened this issue Jan 14, 2025 · 0 comments
Open

NPE while running function from constructor keyword argument #2121

toinehartman opened this issue Jan 14, 2025 · 0 comments

Comments

@toinehartman
Copy link
Contributor

Describe the bug

Evaluating a function-type constructor keyword argument causes null-pointer exception.

To Reproduce

Steps to reproduce the behavior:

import IO;
int fallBackF(int i) {
    return i;
}

data A
    = a(int(int) f = fallBackF)
    | b(int(int) f = int(int i) { return i * 2; })
    ;

// NPE
test bool kwDefault() {
    A aa = a();
    return aa.f(1) == 1;
}

// NPE
test bool inlineKwDefault() {
    A bb = b();
    return bb.f(1) == 2;
}

Workaround: using common keyword arguments (on the ADT instead of constructor) works:

data B(int(int) g = fallBackF, int(int) h = int(int i) { return i * 2; })
    = c()
    ;

// Succeeds
test bool commonKwDefault() {
    B aa = c();
    return aa.g(1) == 1;
}

// Succeeds
test bool inlineCommonKwDefault() {
    B aa = c();
    return aa.h(1) == 2;
}

Expected behavior
Definitely no NPE. All tests should succeed.

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

1 participant