Skip to content

Commit

Permalink
Merge pull request #2051 from usethesource/fix/issue-2049
Browse files Browse the repository at this point in the history
static types of defaults of common keyword parameters were lost
  • Loading branch information
jurgenvinju authored Oct 10, 2024
2 parents 79f030d + 8c88fb4 commit 2b4e741
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/org/rascalmpl/interpreter/result/ConstructorFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ public Result<IValue> computeDefaultKeywordParameter(String label, IConstructor
kwResult = def.interpret(eval);
}

// apply the static type we expect from the declaration:
kwResult = ResultFactory.makeResult(kwType, kwResult.getValue(), ctx);

if (name.equals(label)) {
// we have the one we need, bail out quickly
return kwResult;
}
else {
env.declareVariable(kwResult.getStaticType(), name);
env.declareVariable(kwType, name);
env.storeVariable(name, kwResult);
resultEnv.declareVariable(kwResult.getStaticType(), name);
resultEnv.declareVariable(kwType, name);
resultEnv.storeVariable(name, kwResult);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,13 @@ int outer5(int t, int tabSize=4){

test bool outer5_1() = outer5(1) == 1;
test bool outer5_11() = outer5(11) == 65;
test bool outer5_11_kw() = outer5(11, tabSize=40) == 101;
test bool outer5_11_kw() = outer5(11, tabSize=40) == 101;


data WorkspaceInfo(rel[int a, int b] defines = {}) = workspaceInfo();

@synopsis{a test for issue #2049}
test bool staticTypesOfCommonKeywordDefaults() {
ws = workspaceInfo();
return ws.defines<b,a> == {};
}

0 comments on commit 2b4e741

Please sign in to comment.