rascal icon indicating copy to clipboard operation
rascal copied to clipboard

NPE while running function from constructor keyword argument

Open toinehartman opened this issue 10 months ago • 0 comments

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.

toinehartman avatar Jan 14 '25 13:01 toinehartman