Skip to content

NPE while running function from constructor keyword argument #2121

Open
@toinehartman

Description

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.

Activity

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions