rascal icon indicating copy to clipboard operation
rascal copied to clipboard

Uses of ADT formal keyword arguments refer to full ADT definition

Open toinehartman opened this issue 8 months ago • 0 comments

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

void functionKeywordFormal() {
    println("== Keyword formals (functions) ===");
    tm = typeCheck(
        "int f(int foo, int bar = 1) = foo + bar;
        'int g() = f(1, bar = 2);");
    defs = {d.defined | Define d:<_, _, _, keywordFormalId(), _, _> <- tm.defines};
    uses = invert(tm.useDef)[defs];

    print("Defs - of role `keywordFormalId()`: ");
    iprintln(defs);

    println("`f(...)` call site: <invert(tm.useDef)[(tm.defines<idRole, defined>)[functionId()]]>");
    // No use at the line of the function call, although the keyword argument is used there
    print("Uses - of role `keywordFormalId()`: ");
    iprintln(uses);

    println("======================\n");
}

void dataKeywordFormal2() {
    println("== Keyword formals (ADTs) ===");
    tm = typeCheck(
        "data D(int foo = 1) = d(int bar = 2);
        'void main() {
        '   D x = d();
        '   x.foo = 16;
        '   y = x.foo;
        '}");

    print("Defs - of keyword arguments: ");
    defs = {<d, role> | <d, role> <- (tm.defines<idRole, defined, idRole>)[{keywordFieldId(), keywordFormalId()}]};
    iprintln(defs);

    // The uses of `foo` refer to the full ADT definition
    print("Uses - of ADT `D`");
    iprintln(invert(tm.useDef)[(tm.defines<idRole, defined>)[dataId()]]);

    println("======================\n");
}

Expected behavior The uses of x.foo to refer to the def of int foo instead of data D.

toinehartman avatar Mar 14 '25 14:03 toinehartman