From a8ba8af211e985a12c9b140f3928fe823ab8544f Mon Sep 17 00:00:00 2001 From: paulklint Date: Sun, 29 Sep 2024 14:46:00 +0200 Subject: [PATCH] Take care of type parameters in field update --- .../rascalcore/check/CollectExpression.rsc | 22 ++++++++++++++++-- .../lang/rascalcore/compile/Examples/Tst4.rsc | 23 +++++++++++-------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectExpression.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectExpression.rsc index 4e70ac3a..b30ad8b9 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectExpression.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectExpression.rsc @@ -1053,8 +1053,26 @@ void collect(current:(Expression) ` [ = `", 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 `` of assignment: " + msg)); + } + try { + replType = instantiateRascalTypeParameters(current, replType, bindings, s); + } catch invalidInstantiation(str msg): { + s.report(error(current, "Cannot instantiate rhs type `` 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)); diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst4.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst4.rsc index e5f069f3..abde37ca 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst4.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst4.rsc @@ -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(); //