Skip to content

Commit

Permalink
Take care of type parameters in field update
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Sep 29, 2024
1 parent 1c3b103 commit a8ba8af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,26 @@ void collect(current:(Expression) `<Expression expression> [ <Name field> = <Exp
//c.use(field, {fieldId(), keywordFieldId()});
c.calculate("field update of `<field>`", current, [expression, repl],
AType(Solver s){
fieldType = computeFieldTypeWithADT(s.getType(expression), field, scope, s);
replType = s.getType(repl);
fieldType = computeFieldTypeWithADT(s.getType(expression), field, scope, s);
replType = s.getType(repl);
bindings = ();
try bindings = unifyRascalTypeParams(fieldType, replType, bindings);
catch invalidMatch(str reason):
s.report(error(current, reason));
if(!isEmpty(bindings)){
try {
fieldType = instantiateRascalTypeParameters(field, fieldType, bindings, s);
} catch invalidInstantiation(str msg): {
s.report(error(current, "Cannot instantiate lhs type `<prettyAType(fieldType)>` of assignment: " + msg));
}
try {
replType = instantiateRascalTypeParameters(current, replType, bindings, s);
} catch invalidInstantiation(str msg): {
s.report(error(current, "Cannot instantiate rhs type `<prettyAType(replype)>` of assignment: " + msg));
}
}
checkNonVoid(expression, s, "Base expression of field update`");
checkNonVoid(repl, s, "Replacement expression of field update`");
s.requireSubType(replType, fieldType, error(current, "Cannot assign value of type %t to field %q of type %t", replType, field, fieldType));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
module lang::rascalcore::compile::Examples::Tst4

lrel[str, int, str] main(){
lrel[str, int] X = [<"a", 1>];
lrel[str, int] Y = [<"a", 1>];

lrel[str,int,int] XP = X<0,1, 1>;
lrel[int, str] YP = Y<1,0>;
Z = XP o YP;
return Z;
//return {};
//lrel[str, int, str] main(){
// lrel[str, int] X = [<"a", 1>];
// lrel[str, int] Y = [<"a", 1>];
//
// lrel[str,int,int] XP = X<0,1, 1>;
// lrel[int, str] YP = Y<1,0>;
// Z = XP o YP;
// return Z;
//}
value main(){
rel[value, tuple[int, value]] X = {<0,<1,1>>} ;
rel[tuple[value,int], int] Y = {<<1,1>,2>};
return X o Y;
}
//Met bijv: {<0,<1,1>>} o {<<1,1>,2>} als voorbeeld dat dit oplevert {<0,2>} .

//data Face = top() | left() | right() | bottom();
//
Expand Down

0 comments on commit a8ba8af

Please sign in to comment.