From b816fccf823f93ce2170035c34dc5a92f0779c53 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Mon, 16 Nov 2026 13:37:13 +0100 Subject: [PATCH 01/12] Add utility to filter overloads by type. --- .../compiler/lang/rascalcore/check/ATypeUtils.rsc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index 697640d2347..aaf2e8c14ee 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -1503,4 +1503,9 @@ public AType filterOverloads(overloadedAType(rel[loc, IdRole, AType] overloads), if({<_,_,t>} := reduced) return t; return overloadedAType(reduced); } -public default AType filterOverloads(AType t, set[IdRole] roles) = t; \ No newline at end of file +public default AType filterOverloads(AType t, set[IdRole] roles) = t; + +@synopsis{Filter overloads by ((AType)).} +rel[loc, IdRole, AType] filterOverloads(rel[loc, IdRole, AType] overloads, set[AType] atypes) + // This appears to be a pretty fast way to find the matching overloads, faster than e.g. building a map in advance and looking up here. Note that `==` is required because of keyword arg equality. + = { | atype <- atypes, <- overloads, atype == at}; From b0093f6e578ada02d863cc3d8957771fc4198d6c Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Mon, 16 Nov 2026 13:23:40 +0100 Subject: [PATCH 02/12] Do computations on overload types once per type. --- .../compiler/lang/rascalcore/check/AType.rsc | 24 +++++++++---------- .../lang/rascalcore/check/ATypeBase.rsc | 4 ++-- .../lang/rascalcore/check/ATypeUtils.rsc | 6 ++--- .../rascalcore/check/CollectExpression.rsc | 6 ++--- .../rascalcore/check/CollectOperators.rsc | 8 +++---- .../rascalcore/check/CollectStatement.rsc | 2 +- .../lang/rascalcore/check/ComputeType.rsc | 4 ++-- .../lang/rascalcore/check/RascalConfig.rsc | 8 +++---- .../compile/Rascal2muRascal/RascalPattern.rsc | 4 ++-- .../compile/muRascal2Java/Conversions.rsc | 4 ++-- .../compile/muRascal2Java/Resolvers.rsc | 2 +- 11 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/AType.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/AType.rsc index 2ec6fd344fa..0222ae52280 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/AType.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/AType.rsc @@ -65,8 +65,8 @@ default bool asubtype(AType l, AType r){ case tvar(_): throw TypeUnavailable(); case overloadedAType(overloads): - //TODO: Alternative: return asubtype(l, (\avoid() | alub(it, tp) | <_, _, tp> <- overloads)); - return isEmpty(overloads) ? asubtype(l, avoid()) : any(<_, _, tp> <- overloads, asubtype(l, tp)); + //TODO: Alternative: return asubtype(l, (\avoid() | alub(it, tp) | tp <- overloads<2>)); + return isEmpty(overloads) ? asubtype(l, avoid()) : any(tp <- overloads<2>, asubtype(l, tp)); case avalue(): return true; case anum(): @@ -176,8 +176,8 @@ bool asubtypeLeftTypeParam(p1:aparameter(str n1, AType b1, closed=true), AType r } bool asubtype(overloadedAType(overloads), AType r) - //TODO: Alternative: = asubtype((\avoid() | alub(it, tp) | <_, _, tp> <- overloads), r); - = isEmpty(overloads) ? asubtype(avoid(), r) : any(<_, _, tp> <- overloads, asubtype(tp, r)); + //TODO: Alternative: = asubtype((\avoid() | alub(it, tp) | tp <- overloads<2>), r); + = isEmpty(overloads) ? asubtype(avoid(), r) : any(tp <- overloads<2>, asubtype(tp, r)); bool asubtype(avoid(), AType _) = true; default bool asubtype(AType _, avalue()) = true; @@ -572,12 +572,12 @@ default AType alub(AType s, AType t) AType alub(atypeList(ts1), atypeList(ts2)) = atypeList(alubList(ts1, ts2)); AType alub(overloadedAType(overloads), AType t2) - // TODO:Alternative: alub((\avoid() | alub(it, tp) | <_, _, tp> <- overloads), t2); - = isEmpty(overloads) ? t2 : alub((avalue() | aglb(it, tp) | <_, _, tp> <- overloads), t2); + // TODO:Alternative: alub((\avoid() | alub(it, tp) | tp <- overloads<2>), t2); + = isEmpty(overloads) ? t2 : alub((avalue() | aglb(it, tp) | tp <- overloads<2>), t2); AType alub(AType t1, overloadedAType(overloads)) - //TODO: Alternative: = alub(t1, (\avoid() | alub(it, tp) | <_, _, tp> <- overloads)); - = isEmpty(overloads) ? t1 : alub(t1, (avalue() | aglb(it, tp) | <_, _, tp> <- overloads)); + //TODO: Alternative: = alub(t1, (\avoid() | alub(it, tp) | tp <- overloads<2>)); + = isEmpty(overloads) ? t1 : alub(t1, (avalue() | aglb(it, tp) | tp <- overloads<2>)); AType alub(avalue(), AType t) = avalue(); AType alub(AType s, avalue()) = avalue(); @@ -783,12 +783,12 @@ public AType aglb(arel(AType s), aset(AType t)) = aset(aglb(atuple(s), t)); AType aglb(arel(atypeList(list[AType] l)), arel(atypeList(list[AType] r))) = size(l) == size(r) ? arel(atypeList(aglbList(l, r))) : aset(avalue()); AType aglb(overloadedAType(overloads), AType t2) - //TODO: Alternative: = aglb((\avoid() | alub(it, tp) | <_, _, tp> <- overloads), t2); - = isEmpty(overloads) ? t2 : aglb((avoid() | alub(it, tp) | <_, _, tp> <- overloads), t2); + //TODO: Alternative: = aglb((\avoid() | alub(it, tp) | tp <- overloads<2>), t2); + = isEmpty(overloads) ? t2 : aglb((avoid() | alub(it, tp) | tp <- overloads<2>), t2); AType aglb(AType t1, overloadedAType(overloads)) - //TODO: Alternative: = aglb(t1, (\avoid() | alub(it, tp) | <_, _, tp> <- overloads)); - = isEmpty(overloads) ? t1 : aglb(t1, (avoid() | alub(it, tp) | <_, _, tp> <- overloads)); + //TODO: Alternative: = aglb(t1, (\avoid() | alub(it, tp) | tp <- overloads<2>)); + = isEmpty(overloads) ? t1 : aglb(t1, (avoid() | alub(it, tp) | tp <- overloads<2>)); public AType aglb(alist(AType s), alist(AType t)) = alist(aglb(s, t)); public AType aglb(alist(AType s), alrel(AType t)) = alist(aglb(s,atuple(t))); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeBase.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeBase.rsc index bda7c86441b..b33340fa405 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeBase.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeBase.rsc @@ -92,12 +92,12 @@ data AType (str alabel = "") @memo={expireAfter(minutes=5),maximumSize(1000)} AType overloadedAType(rel[loc, IdRole, AType] overloads){ - if(all( <- overloads, aadt(_, _, _) := t)){ + if(all(aadt(_, _, _) <- overloads<2>)){ str adtName = ""; list[AType] adtParams = []; synRoles = {}; nformals = -1; - for( <- overloads, aadt(adtName1, params1, syntaxRole1) := t){ + for(aadt(adtName1, params1, syntaxRole1) <- overloads<2>){ if(!isEmpty(adtName) && adtName != adtName1) fail overloadedAType; // overloading of different ADTs. if(nformals >= 0 && size(params1) != nformals) fail overloadedAType; else nformals = size(params1); // different type parameter arities diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index aaf2e8c14ee..601697ac4a6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -102,7 +102,7 @@ str prettyAType(areified(AType t)) = "type[]"; // utilities str prettyAType(overloadedAType(rel[loc, IdRole, AType] overloads)) - = intercalateOr([prettyAType(t1) | t1 <- {t | <_, _, t> <- overloads} ]); + = intercalateOr([prettyAType(t1) | t1 <- {t | t <- overloads<2>} ]); str prettyAType(list[AType] atypes) = intercalate(", ", [prettyAType(t) | t <- atypes]); @@ -211,7 +211,7 @@ Symbol atype2symbol1(areified(AType t)) = Symbol::reified(atype2symbol(t)); // overloaded types (union types) do not exist at the Rascal runtime level, // so we lub the alternatives here which is what happens at run-time as well. Symbol atype2symbol1(overloadedAType(rel[loc, IdRole, AType] overloads)) - = atype2symbol((\avoid() | alub(it, alt) | <_, _, alt> <- overloads)); + = atype2symbol((\avoid() | alub(it, alt) | alt <- overloads<2>)); list[Symbol] atypes2symbols(list[AType] atypes) = [atype2symbol(t) | t <- atypes]; @@ -658,7 +658,7 @@ bool hasKeywordParameters(acons(AType adt, list[AType] fields, list[Keyword] kwF = !isEmpty(kwFields); bool hasKeywordParameters(overloadedAType(overloads)) - = any( <- overloads, hasKeywordParameters(t)); + = any(t <- overloads<2>, hasKeywordParameters(t)); default bool hasKeywordParameters(AType t) = false; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectExpression.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectExpression.rsc index c4fae5bd748..c219182d5fa 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectExpression.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectExpression.rsc @@ -714,10 +714,10 @@ void reportMissingNonTerminalCases(Expression current, rel[loc def, IdRole idRol for(int i <- index(actuals)){ actual_type = s.getType(actuals[i]); if(isNonTerminalAType(actual_type)){ - if(!isEmpty(validOverloads) && all(ovl <- validOverloads, - arg_types := getFunctionOrConstructorArgumentTypes(ovl.atype), + if(!isEmpty(validOverloads) && all(atype <- validOverloads<2>, + arg_types := getFunctionOrConstructorArgumentTypes(atype), size(arg_types) == size(actuals), isADTAType(arg_types[i]), getADTName(arg_types[i]) == "Tree")){ - nont = [ovl.atype | ovl <- overloads, arg_types := getFunctionOrConstructorArgumentTypes(ovl.atype), size(arg_types) == size(actuals), isNonTerminalAType(arg_types[i]) ]; + nont = [atype | atype <- overloads<2>, arg_types := getFunctionOrConstructorArgumentTypes(atype), size(arg_types) == size(actuals), isNonTerminalAType(arg_types[i]) ]; if(!isEmpty(nont)){ s.report(info(current, "Actual #%v has nonterminal type %t, but only comparable overloads with `Tree` argument exist, maybe missing import/extend?", i, actual_type)); } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc index 6501a9ef264..14e4847ecc2 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc @@ -48,7 +48,7 @@ void collect(current: (Expression) ` is `, Collector c){ private AType do_computeIsType(Tree current, AType t1, Solver s){ // TODO: check that name exists if(overloadedAType(rel[loc, IdRole, AType] overloads) := t1){ - for(<_, _, tp> <- overloads){ + for(tp <- overloads<2>){ try return do_computeIsType(current, tp, s); catch checkFailed(_): /* ignore, try next */; catch NoBinding(): /* ignore, try next */; @@ -67,7 +67,7 @@ void collect(current: (Expression) ` has `, Collector c){ private AType _computeHasType(Tree current, AType t1, Solver s){ if(overloadedAType(rel[loc, IdRole, AType] overloads) := t1){ - for(<_, _, tp> <- overloads){ + for(tp <- overloads<2>){ try return _computeHasType(current, tp, s); catch checkFailed(_): /* ignore, try next */; catch NoBinding(): /* ignore, try next */; @@ -649,7 +649,7 @@ void collect(current: (Expression) ` \<- `, s.fact(pat, patType); } if(overloadedAType(rel[loc, IdRole, AType] overloads) := elmType){ - for(<_, _, tp> <- overloads){ + for(tp <- overloads<2>){ if(comparable(patType, tp)) return abool(); } s.report(error(pat, "Pattern of type %t cannot be used to enumerate over %t", patType, exprType)); @@ -696,7 +696,7 @@ AType computeEnumeratorElementType(Expression current, AType etype, Solver s) { } else if (isOptType(etype)) { return getOptType(etype); } else if(overloadedAType(rel[loc, IdRole, AType] overloads) := etype){ - for(<_, _, tp> <- overloads, isEnumeratorType(tp)){ + for(tp <- overloads<2>, isEnumeratorType(tp)){ try { return computeEnumeratorElementType(current, tp, s); } catch checkFailed(list[FailMessage] _): /* do nothing and try next overload*/; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc index 3104ee7c08e..08282cf86a9 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc @@ -1168,7 +1168,7 @@ private AType computeAnnoAssignableType(Statement current, AType receiverType, N if (isNodeAType(receiverType) || isADTAType(receiverType) || isNonTerminalAType(receiverType)) { if(overloadedAType(rel[loc, IdRole, AType] overloads) := annoNameType){ anno_overloads = {}; - for( <- overloads, aanno(_, onType, tp2) := tp1, asubtype(receiverType, onType)){ + for( <- overloads, aanno(_, onType, _) := tp1, asubtype(receiverType, onType)){ anno_overloads += ; } if(isEmpty(anno_overloads)) s.report(error(current, "Annotation on %t cannot be resolved from %t", receiverType, annoNameType)); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc index 23fdcd4a264..7af8c872453 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc @@ -332,7 +332,7 @@ AType computeADTReturnType(Tree current, str adtName, loc scope, list[AType] for list[AType] parameters = []; if(overloadedAType(rel[loc, IdRole, AType] overloads) := adtType){ params = {}; - for(<_, _, tp> <- overloads){ + for(tp <- overloads<2>){ if(isADTAType(tp)) params += toSet(getADTTypeParameters(tp)); } parameters = toList(params); @@ -460,7 +460,7 @@ list[Keyword] getCommonKeywords(aadt(str adtName, list[AType] parameters, _), lo } -list[Keyword] getCommonKeywords(overloadedAType(rel[loc, IdRole, AType] overloads), loc scope, Solver s) = [ *getCommonKeywords(adt, scope, s) | <_, _, adt> <- overloads ]; +list[Keyword] getCommonKeywords(overloadedAType(rel[loc, IdRole, AType] overloads), loc scope, Solver s) = [ *getCommonKeywords(adt, scope, s) | adt <- overloads<2> ]; default list[Keyword] getCommonKeywords(AType atype, loc scope, Solver s) = []; public AType computeFieldTypeWithADT(AType containerType, Tree field, loc scope, Solver s) { diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc index c5eea71a920..19302f88c7d 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc @@ -545,13 +545,11 @@ void checkOverloadedConstructors(Tree t, Solver s){ } void reportConstructorOverload(Expression current, overloadedAType(rel[loc def, IdRole idRole, AType atype] overloads), Solver s){ - coverloads = [ ovl | ovl <- overloads, isConstructorAType(ovl.atype) ]; - if(size(coverloads) > 1){ - ovl1 = coverloads[0]; - adtNames = { adtName | <- overloads, acons(ret:aadt(adtName, list[AType] _, _), list[AType] fields, list[Keyword] kwFields) := tp }; + if(atype <- overloads.atype, isConstructorAType(atype)){ + adtNames = { adtName | acons(ret:aadt(adtName, list[AType] _, _), list[AType] fields, list[Keyword] kwFields) <- overloads<2>}; qualifyHint = size(adtNames) > 1 ? " you may use as qualifier" : ""; argHint = "make argument type(s) more precise"; - msg = error("Constructor `` is overloaded, maybe", + msg = error("Constructor `` is overloaded, maybe", current.src); s.addMessages([msg]); } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc index fc3c34e23ca..e1abcea5fb5 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc @@ -1180,8 +1180,8 @@ MuExp translatePat(p:(Pattern) ` ( <{Pattern ","}* arguments if(expType.alabel?){ qname = expType.alabel; } else if(overloadedAType(rel[loc, IdRole, AType] overloads) := expType, - any(<_, _, tp> <- overloads, tp.alabel?)){ - for(<_, _, tp> <- overloads){ + any(tp <- overloads<2>, tp.alabel?)){ + for(tp <- overloads<2>){ if(tp.alabel?){ qname = tp.alabel; break; } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Conversions.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Conversions.rsc index 5e90764f230..b04ec98f3fa 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Conversions.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Conversions.rsc @@ -138,7 +138,7 @@ str atype2idpart(t:acons(AType adt, list[AType] fields, list[Keyword] kwFields)) str atype2idpart(overloadedAType(rel[loc, IdRole, AType] overloads)){ resType = avoid(); formalsType = avoid(); - for(<_, _, tp> <- overloads){ + for(tp <- overloads<2>){ resType = alub(resType, getResult(tp)); formalsType = alub(formalsType, atypeList(getFormals(tp))); } @@ -264,7 +264,7 @@ str atype2IValue1(at:acons(AType adt, list[AType] fields, list[Keyword] kwFields str atype2IValue1(overloadedAType(rel[loc, IdRole, AType] overloads), map[AType, set[AType]] defs){ resType = avoid(); formalsType = avoid(); - for(<_, _, tp> <- overloads){ + for(tp <- overloads<2>){ resType = alub(resType, getResult(tp)); formalsType = alub(formalsType, atypeList(getFormals(tp))); } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc index a8f6f6918e4..8f47ea0be3c 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc @@ -105,7 +105,7 @@ str varName(muVarKwp(str name, loc _, AType _)){ // duplicate, see Co //str vtypeisatype(str e, AType t, JGenie jg) = ".getType().comparable()"; str vtypeisatype(str e, str etype, overloadedAType(rel[loc, IdRole, AType] overloads), JGenie jg) - = " instanceof IConstructor && ).getConstructorType().equivalent()" | <_, _, tp> <- overloads])>"; + = " instanceof IConstructor && ).getConstructorType().equivalent()" | tp <- overloads<2>])>"; //str vtypeisatype(str e, t:acons(AType adt, list[AType] fields, list[Keyword] kwFields), JGenie jg) // = ".getConstructorType().comparable()"; From ff29c7fd40750470cb153840911d4317a8a0660a Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Mon, 16 Nov 2026 13:40:22 +0100 Subject: [PATCH 03/12] Do not filter overloads where only type is needed. --- .../lang/rascalcore/check/ComputeType.rsc | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc index 7af8c872453..e9972c583b8 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc @@ -78,31 +78,32 @@ void checkNonVoid(Tree e, AType t, Solver s, str msg){ AType(Solver) makeGetSyntaxType(Type varType) = AType(Solver s) { Tree t = varType; return getSyntaxType(t, s); }; -rel[loc key, IdRole idRole, AType atype] - checkAndFilterOverloads(Tree expr, rel[loc key, IdRole idRole, AType atype] overloads, AType expected, Solver s){ - - rel[loc key, IdRole idRole, AType atype] filteredOverloads = {}; - rel[loc key, IdRole idRole, AType atype] unResolvedConstructorOverloads = {}; - for(tup:<_, _, tp> <- overloads){ +rel[loc key, IdRole idRole, AType atype] checkAndFilterOverloads(Tree expr, rel[loc, IdRole, AType] overloads, AType expected, Solver s) + = filterOverloads(overloads, checkAndFilterOverloadTypes(expr, overloads, expected, s)); + +set[AType] checkAndFilterOverloadTypes(Tree expr, rel[loc key, IdRole idRole, AType atype] overloads, AType expected, Solver s) { + set[AType] filteredTypes = {}; + set[AType] unResolvedConstructorOverloads = {}; + for(tp <- overloads<2>){ if(isValueAType(expected)){ - filteredOverloads += tup; + filteredTypes += tp; if(isConstructorAType(tp) || isADTAType(tp)){ - unResolvedConstructorOverloads += tup; + unResolvedConstructorOverloads += tp; } } else if(asubtype(tp, expected)){ - filteredOverloads += tup; + filteredTypes += tp; } else if(isConstructorAType(tp) || isADTAType(tp)){ - unResolvedConstructorOverloads += tup; + unResolvedConstructorOverloads += tp; } } if(size(unResolvedConstructorOverloads) > 1){ - adtNames = { getADTName(tp) | <_, _, tp> <- unResolvedConstructorOverloads }; + adtNames = { getADTName(tp) | tp <- unResolvedConstructorOverloads }; qualifyHint = size(adtNames) > 1 ? "you may use as qualifier" : ""; argHint = "make argument type(s) more precise"; msg = error(expr, "Expression `` is overloaded, to resolve it "); s.report(msg); } - return filteredOverloads; + return filteredTypes; } void(Solver) makeVarInitRequirement(Variable var) @@ -122,8 +123,8 @@ void(Solver) makeVarInitRequirement(Variable var) initialTypeU = instantiateRascalTypeParameters(var, initialTypeU, bindings, s); if(s.isFullyInstantiated(initialTypeU)){ if(overloadedAType(overloads) := initialTypeU){ - filteredOverloads = checkAndFilterOverloads(var.initial, overloads, varTypeU, s); - for(<_, _, tp> <- filteredOverloads){ + types = checkAndFilterOverloadTypes(var.initial, overloads, varTypeU, s); + for(tp <- types){ s.requireSubType(tp, varTypeU, error(var, "Initialization of %q should be subtype of %t, found overloaded type %t", "", var.name, deUnique(initialTypeU))); } } else { From 66910888febdfabe06dd6e2c3c1af1619db04aef Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 17 Nov 2026 11:51:03 +0100 Subject: [PATCH 04/12] Compute overloaded type of operator once per type. --- .../lang/rascalcore/check/ATypeUtils.rsc | 16 +++++ .../rascalcore/check/CollectOperators.rsc | 12 +--- .../rascalcore/check/CollectStatement.rsc | 10 +-- .../lang/rascalcore/check/ComputeType.rsc | 68 +++---------------- 4 files changed, 33 insertions(+), 73 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index 601697ac4a6..418f307f37c 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -1509,3 +1509,19 @@ public default AType filterOverloads(AType t, set[IdRole] roles) = t; rel[loc, IdRole, AType] filterOverloads(rel[loc, IdRole, AType] overloads, set[AType] atypes) // This appears to be a pretty fast way to find the matching overloads, faster than e.g. building a map in advance and looking up here. Note that `==` is required because of keyword arg equality. = { | atype <- atypes, <- overloads, atype == at}; + +AType computeOverloads(overloadedAType(rel[loc def, IdRole idRole, AType atype] overloads), AType(AType) f) { + set[AType] computedTypes = {}; + for (tp <- overloads.atype) { + try { + computedTypes += f(tp); + } catch checkFailed(list[FailMessage] _): /* continue with next overload */; + catch NoBinding(): /* continue with next overload */; + catch _: /* continue with next overload */; + } + + if (isEmpty(filteredTypes)) return overloadedAType({}); + return overloadedAType(filteredOverloads(overloads, computedTypes)); +} + +default AType computeOverloads(AType at, AType(AType) _) = at; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc index 14e4847ecc2..f2dfb23ca10 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc @@ -670,16 +670,8 @@ AType computeEnumeratorElementType(Expression current, AType etype, Solver s) { etype = s.instantiate(etype); - if(overloadedAType(rel[loc, IdRole, AType] overloads) := etype){ - filtered_overloads = {}; - for( <- overloads){ - try { - filtered_overloads += ; - } catch checkFailed(_): /* ignore, try next */; - catch NoBinding(): /* ignore, try next */; - //>> catch e: /* ignore, try next */; - } - if(!isEmpty(filtered_overloads)) return overloadedAType(filtered_overloads); + if(ovl:overloadedAType(filtered_overloads:{_, *_}) := computeOverloads(overloads, AType(AType tp) { return computeEnumeratorElementType(current, tp, s); })) { + if(!isEmpty(filtered_overloads)) return ovl; s.report(error(current, "Type %t is not enumerable", etype)); } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc index 08282cf86a9..870b43ecda3 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc @@ -853,16 +853,16 @@ private AType computeSubscriptAssignableType(Statement current, AType receiverTy checkNonVoid(current, rhs, s, "Righthand side of subscript assignment"); if(overloadedAType(rel[loc, IdRole, AType] overloads) := receiverType){ - sub_overloads = {}; - for( <- overloads){ + sub_overloadTypes = {}; + for(tp <- overloads<2>){ try { - sub_overloads += ; + sub_overloadTypes += computeSubscriptAssignableType(current, tp, subscript, operator, rhs, s); } catch checkFailed(list[FailMessage] _): /* do nothing and try next overload */; catch NoBinding(): /* do nothing and try next overload */; //>> catch e: /* do nothing and try next overload */; } - if(isEmpty(sub_overloads)) s.report(error(current, "Subscript %q of %t cannot be resolved", subscript, receiverType)); - return overloadedAType(sub_overloads); + if(isEmpty(sub_overloadTypes)) s.report(error(current, "Subscript %q of %t cannot be resolved", subscript, receiverType)); + return overloadedAType(filterOverloads(overloads, sub_overloadTypes)); } subscriptType = s.getType(subscript); // TODO: overloaded? diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc index e9972c583b8..179ab02f4c7 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc @@ -144,17 +144,9 @@ AType unaryOp(str op, AType(Tree, AType, Solver) computeType, Tree current, ATyp requireFullyInstantiated(s, t1); - if(overloadedAType(rel[loc, IdRole, AType] overloads) := t1){ - bin_overloads = {}; - for( <- overloads){ - try { - bin_overloads += ; - } catch checkFailed(list[FailMessage] _): /* continue with next overload */; - catch NoBinding(): /* continue with next overload */; -//>> catch e: /* continue with next overload */; - } + if(ovl:overloadedAType(bin_overloads) := computeOverloads(overloads, AType(AType tp) { return unaryOp(op, computeType, current, tp, s); })) { if(isEmpty(bin_overloads)) s.report(error(current, "%q cannot be applied to %t", op, t1)); - return overloadedAType(bin_overloads); + return ovl; } if(!maybeVoid && isVoidAType(t1)) s.report(error(current, "%q cannot be applied to argument of type `void`", op)); return computeType(current, t1, s); @@ -164,30 +156,14 @@ AType binaryOp(str op, AType(Tree, AType, AType, Solver) computeType, Tree curre requireFullyInstantiated(s, t1, t2); - if(overloadedAType(rel[loc, IdRole, AType] overloads) := t1){ - bin_overloads = {}; - for( <- overloads){ - try { - bin_overloads += ; - } catch checkFailed(list[FailMessage] _): /* continue with next overload */; - catch NoBinding(): /* continue with next overload */; -//>> catch e: /* continue with next overload */; - } + if(ovl:overloadedAType(bin_overloads) := computeOverloads(t1, AType(AType tp) { return binaryOp(op, computeType, current, tp, t2, s); })) { if(isEmpty(bin_overloads)) s.report(error(current, "%q cannot be applied to %t and %t", op, t1, t2)); - return overloadedAType(bin_overloads); + return ovl; } - if(overloadedAType(rel[loc, IdRole, AType] overloads) := t2){ - bin_overloads = {}; - for( <- overloads){ - try { - bin_overloads += < key, idr, binaryOp(op, computeType, current, t1, tp, s)>; - } catch checkFailed(list[FailMessage] _):/* continue with next overload */; - catch NoBinding(): /* continue with next overload */; -//>> catch e: /* continue with next overload */; - } + if(ovl:overloadedAType(bin_overloads) := computeOverloads(t2, AType(AType tp) { return binaryOp(op, computeType, current, t1, tp, s); })) { if(isEmpty(bin_overloads)) s.report(error(current, "%q cannot be applied to %t and %t", op, t1, t2)); - return overloadedAType(bin_overloads); + return ovl; } if(isVoidAType(t1) || isVoidAType(t2)) s.report(error(current, "%q cannot be applied to argument of type `void`", op)); return computeType(current, t1, t2, s); @@ -197,41 +173,17 @@ AType ternaryOp(str op, AType(Tree, AType, AType, AType, Solver) computeType, Tr requireFullyInstantiated(s, t1, t2, t3); - if(overloadedAType(rel[loc, IdRole, AType] overloads) := t1){ - tern_overloads = {}; - for( <- overloads){ - try { - tern_overloads += ; - } catch checkFailed(list[FailMessage] _): /* continue with next overload */; - catch NoBinding(): /* continue with next overload */; - catch _: /* continue with next overload */; - } + if(ovl:overloadedAType(tern_overloads) := computeOverloads(t1, AType(AType tp) { return ternaryOp(op, computeType, current, tp, t2, t3, s); })) { if(isEmpty(tern_overloads)) s.report(error(current, "%q cannot be applied to %t, %t, and %t", op, t1, t2, t3)); - return overloadedAType(tern_overloads); + return ovl; } - if(overloadedAType(rel[loc, IdRole, AType] overloads) := t2){ - tern_overloads = {}; - for( <- overloads){ - try { - tern_overloads += < key, idr, ternaryOp(op, computeType, current, t1, tp, t3, s)>; - } catch checkFailed(list[FailMessage] _):/* continue with next overload */; - catch NoBinding(): /* continue with next overload */; - //>> catch e:/* continue with next overload */; - } + if(ovl:overloadedAType(tern_overloads) := computeOverloads(t2, AType(AType tp) { return ternaryOp(op, computeType, current, t1, tp, t3, s); })) { if(isEmpty(tern_overloads)) s.report(error(current, "%q cannot be applied to %t, %t, and %t", op, t1, t2, t3)); return overloadedAType(tern_overloads); } - if(overloadedAType(rel[loc, IdRole, AType] overloads) := t3){ - tern_overloads = {}; - for( <- overloads){ - try { - tern_overloads += < key, idr, ternaryOp(op, computeType, current, t1, t2, tp, s)>; - } catch checkFailed(list[FailMessage] _): /* continue with next overload */; - catch NoBinding(): /* continue with next overload */; - //>> catch e: /* continue with next overload */; - } + if(overloadedAType(tern_overloads) := computeOverloads(t3, AType(AType tp) { return ternaryOp(op, computeType, current, t1, t2, tp, s); })) { if(isEmpty(tern_overloads)) s.report(error(current, "%q cannot be applied to %t, %t, and %t", op, t1, t2, t3)); return overloadedAType(tern_overloads); } From 7644a2a5c867078b8549e76f0c66c426546df702 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Mon, 16 Nov 2026 15:17:26 +0100 Subject: [PATCH 05/12] Simplify & improve overload filtering. --- .../rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index 418f307f37c..21beb2e2982 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -1507,8 +1507,7 @@ public default AType filterOverloads(AType t, set[IdRole] roles) = t; @synopsis{Filter overloads by ((AType)).} rel[loc, IdRole, AType] filterOverloads(rel[loc, IdRole, AType] overloads, set[AType] atypes) - // This appears to be a pretty fast way to find the matching overloads, faster than e.g. building a map in advance and looking up here. Note that `==` is required because of keyword arg equality. - = { | atype <- atypes, <- overloads, atype == at}; + = {t | t:<_, _, atype> <- overloads, atype in atypes}; AType computeOverloads(overloadedAType(rel[loc def, IdRole idRole, AType atype] overloads), AType(AType) f) { set[AType] computedTypes = {}; From 7ff566603381dfb8e6b5fd0c795ba14274a391ce Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 17 Nov 2026 11:41:48 +0100 Subject: [PATCH 06/12] Extract filter-and-retype utility. --- .../compiler/lang/rascalcore/check/ATypeUtils.rsc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index 21beb2e2982..da82152bc66 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -1509,6 +1509,11 @@ public default AType filterOverloads(AType t, set[IdRole] roles) = t; rel[loc, IdRole, AType] filterOverloads(rel[loc, IdRole, AType] overloads, set[AType] atypes) = {t | t:<_, _, atype> <- overloads, atype in atypes}; +@synopsis{Filter overloads by ((AType)) and map their type.} +rel[loc, IdRole, AType] filterAndRetypeOverloads(rel[loc, IdRole, AType] overloads, rel[AType, AType] atypes) + = {> | <- overloads, atype <- atypes, atype<0> == ovlType}; + + AType computeOverloads(overloadedAType(rel[loc def, IdRole idRole, AType atype] overloads), AType(AType) f) { set[AType] computedTypes = {}; for (tp <- overloads.atype) { @@ -1523,4 +1528,4 @@ AType computeOverloads(overloadedAType(rel[loc def, IdRole idRole, AType atype] return overloadedAType(filteredOverloads(overloads, computedTypes)); } -default AType computeOverloads(AType at, AType(AType) _) = at; +default AType computeOverloads(AType at, AType(AType) _) = at; \ No newline at end of file From bc3d02f1e378eca104ef9dd56a3481f2a1120d02 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 17 Nov 2026 12:15:20 +0100 Subject: [PATCH 07/12] Fix operator overload computation. --- .../compiler/lang/rascalcore/check/ATypeUtils.rsc | 8 ++++---- .../lang/rascalcore/check/CollectOperators.rsc | 2 +- .../lang/rascalcore/check/CollectStatement.rsc | 10 +--------- .../compiler/lang/rascalcore/check/ComputeType.rsc | 2 +- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index da82152bc66..4b984d0f3e8 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -1515,17 +1515,17 @@ rel[loc, IdRole, AType] filterAndRetypeOverloads(rel[loc, IdRole, AType] overloa AType computeOverloads(overloadedAType(rel[loc def, IdRole idRole, AType atype] overloads), AType(AType) f) { - set[AType] computedTypes = {}; + rel[AType, AType] computedTypes = {}; for (tp <- overloads.atype) { try { - computedTypes += f(tp); + computedTypes += ; } catch checkFailed(list[FailMessage] _): /* continue with next overload */; catch NoBinding(): /* continue with next overload */; catch _: /* continue with next overload */; } if (isEmpty(filteredTypes)) return overloadedAType({}); - return overloadedAType(filteredOverloads(overloads, computedTypes)); + return overloadedAType(filterAndRetypeOverloads(overloads, computedTypes)); } -default AType computeOverloads(AType at, AType(AType) _) = at; \ No newline at end of file +default AType computeOverloads(AType at, AType(AType) _) = at; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc index f2dfb23ca10..ed2606e05b0 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectOperators.rsc @@ -670,7 +670,7 @@ AType computeEnumeratorElementType(Expression current, AType etype, Solver s) { etype = s.instantiate(etype); - if(ovl:overloadedAType(filtered_overloads:{_, *_}) := computeOverloads(overloads, AType(AType tp) { return computeEnumeratorElementType(current, tp, s); })) { + if(ovl:overloadedAType(filtered_overloads:{_, *_}) := computeOverloads(etype, AType(AType tp) { return computeEnumeratorElementType(current, tp, s); })) { if(!isEmpty(filtered_overloads)) return ovl; s.report(error(current, "Type %t is not enumerable", etype)); } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc index 870b43ecda3..bac2e3b70e3 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc @@ -1150,15 +1150,7 @@ private AType computeAnnoAssignableType(Statement current, AType receiverType, N if(!s.isFullyInstantiated(receiverType)) throw TypeUnavailable(); if(!s.isFullyInstantiated(rhs)) throw TypeUnavailable(); - if(overloadedAType(rel[loc, IdRole, AType] overloads) := receiverType){ - anno_overloads = {}; - for( <- overloads){ - try { - anno_overloads += ; - } catch checkFailed(list[FailMessage] fms): /* do nothing and try next overload */; - catch NoBinding(): /* do nothing and try next overload */; - //>> catch e: /* do nothing and try next overload */; - } + if(overloadedAType(anno_overloads:{_, *_}) := computeOverloads(receiverType, AType(AType tp) { return computeAnnoAssignableType(current, tp, annoName, operator, rhs, scope, s); })) { if(isEmpty(anno_overloads)) s.report(error(current, "Annotation on %t cannot be resolved", receiverType)); return overloadedAType(anno_overloads); } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc index 179ab02f4c7..cdbf3c5f6a2 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc @@ -144,7 +144,7 @@ AType unaryOp(str op, AType(Tree, AType, Solver) computeType, Tree current, ATyp requireFullyInstantiated(s, t1); - if(ovl:overloadedAType(bin_overloads) := computeOverloads(overloads, AType(AType tp) { return unaryOp(op, computeType, current, tp, s); })) { + if(ovl:overloadedAType(bin_overloads) := computeOverloads(t1, AType(AType tp) { return unaryOp(op, computeType, current, tp, s); })) { if(isEmpty(bin_overloads)) s.report(error(current, "%q cannot be applied to %t", op, t1)); return ovl; } From c4b3f7806d2f58443867b2407ffe711ce12f9bb6 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 17 Nov 2026 12:16:21 +0100 Subject: [PATCH 08/12] Filter overloaded patterns once per type. --- .../compiler/lang/rascalcore/check/ComputeType.rsc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc index cdbf3c5f6a2..4ed7b0ece75 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc @@ -1214,19 +1214,18 @@ private bool acceptable(int i, AType a, AType b, list[bool] uninstantiated) tuple[rel[loc, IdRole, AType], list[bool]] filterOverloadedConstructors(rel[loc, IdRole, AType] overloads, list[AType] argTypes, AType subjectType, Solver s){ int arity = size(argTypes); - rel[loc, IdRole, AType] filteredOverloads = {}; + set[AType] filteredTypes = {}; list[bool] identicalFields = [true | int _ <- [0 .. arity]]; uninstantiated = [ !s.isFullyInstantiated(argTypes[i]) | int i <- [0 .. arity] ]; - for(ovl: <- overloads){ - if(acons(ret:aadt(_, list[AType] _, _), list[AType] fields, list[Keyword] _) := tp, comparable(ret, subjectType)){ - if(size(fields) == arity && (arity == 0 || all(int i <- index(fields), acceptable(i, fields[i], argTypes[i], uninstantiated)))){ - filteredOverloads += ovl; - } + for(tp:acons(ret:aadt(_, list[AType] _, _), list[AType] fields, list[Keyword] _) <- overloads<2>, comparable(ret, subjectType)) { + if(size(fields) == arity && (arity == 0 || all(int i <- index(fields), acceptable(i, fields[i], argTypes[i], uninstantiated)))){ + filteredTypes += tp; } } - return ; + + return ; } AType computePatternNodeType(Tree current, loc scope, list[Pattern] patList, (KeywordArguments[Pattern]) ``, Solver s, AType subjectType){ From 483b9caf4bd4f0ca2e1ac56ea3811cee2738bfb0 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 17 Nov 2026 15:51:00 +0100 Subject: [PATCH 09/12] Fix constructor overload detection. --- .../compiler/lang/rascalcore/check/RascalConfig.rsc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc index 19302f88c7d..d8f4e7a2688 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc @@ -545,11 +545,13 @@ void checkOverloadedConstructors(Tree t, Solver s){ } void reportConstructorOverload(Expression current, overloadedAType(rel[loc def, IdRole idRole, AType atype] overloads), Solver s){ - if(atype <- overloads.atype, isConstructorAType(atype)){ + coverloads = [ovl | ovl <- overloads, isConstructorAType(ovl.atype)]; + if(size(coverloads) > 1) { + ovl1 = coverloads[0]; adtNames = { adtName | acons(ret:aadt(adtName, list[AType] _, _), list[AType] fields, list[Keyword] kwFields) <- overloads<2>}; qualifyHint = size(adtNames) > 1 ? " you may use as qualifier" : ""; argHint = "make argument type(s) more precise"; - msg = error("Constructor `` is overloaded, maybe", + msg = error("Constructor `` is overloaded, maybe", current.src); s.addMessages([msg]); } From 2bae2cdeb4e8f48acb219f4603fac2b64fc28d41 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 17 Nov 2026 15:51:41 +0100 Subject: [PATCH 10/12] Flatten prettyType. --- src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index 4b984d0f3e8..1c33f0f0017 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -102,7 +102,7 @@ str prettyAType(areified(AType t)) = "type[]"; // utilities str prettyAType(overloadedAType(rel[loc, IdRole, AType] overloads)) - = intercalateOr([prettyAType(t1) | t1 <- {t | t <- overloads<2>} ]); + = intercalateOr([prettyAType(t1) | t1 <- overloads<2> ]); str prettyAType(list[AType] atypes) = intercalate(", ", [prettyAType(t) | t <- atypes]); From 67946a36b3e72a1f461792929d9816309e4df545 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 17 Nov 2026 16:11:15 +0100 Subject: [PATCH 11/12] Refactor more overload computations. --- .../lang/rascalcore/check/CollectStatement.rsc | 6 +++--- .../compiler/lang/rascalcore/check/ComputeType.rsc | 11 +---------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc index 0f0193cddbe..201d11d7e03 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectStatement.rsc @@ -1162,11 +1162,11 @@ private AType computeAnnoAssignableType(Statement current, AType receiverType, N if (isNodeAType(receiverType) || isADTAType(receiverType) || isNonTerminalAType(receiverType)) { if(overloadedAType(rel[loc, IdRole, AType] overloads) := annoNameType){ anno_overloads = {}; - for( <- overloads, aanno(_, onType, _) := tp1, asubtype(receiverType, onType)){ - anno_overloads += ; + for( <- overloads, asubtype(receiverType, onType)){ + anno_overloads += tp1; } if(isEmpty(anno_overloads)) s.report(error(current, "Annotation on %t cannot be resolved from %t", receiverType, annoNameType)); - return overloadedAType(anno_overloads); + return overloadedAType({ | <- overloads, atype in anno_overloads}); } else if(aanno(_, onType, annoType) := annoNameType){ return annoNameType; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc index c380be59122..62726423cc7 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ComputeType.rsc @@ -541,16 +541,7 @@ AType computeSubscriptionType(Tree current, AType t1, list[AType] tl, list[Expre if(!s.isFullyInstantiated(tp)) throw TypeUnavailable(); } - if(overloadedAType(rel[loc, IdRole, AType] overloads) := t1){ - //println("computeSubscriptionType: , "); - subscript_overloads = {}; - for( <- overloads){ - try { - subscript_overloads += ; - } catch checkFailed(list[FailMessage] _):/* continue with next overload */; - catch NoBinding(): /* continue with next overload */; - //>>> catch e: /* continue with next overload */; - } + if(overloadedAType(subscript_overloads:{_, *_}) := computeOverloads(t1, AType(AType tp) { return computeSubscriptionType(current, tp, tl, indexList, s); })) { //println("computeSubscriptionType: , , ==\> "); if(isEmpty(subscript_overloads)) s.report(error(current, "Expressions of type %t cannot be subscripted", t1)); return overloadedAType(subscript_overloads); From d845069ae653e8a71ff80986b8125c7bd9b91d6a Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 17 Nov 2026 16:41:11 +0100 Subject: [PATCH 12/12] Short-circuit type param check. --- .../rascalmpl/compiler/lang/rascalcore/check/ATypeParamBase.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeParamBase.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeParamBase.rsc index fbc04550e51..4886940bb29 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeParamBase.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeParamBase.rsc @@ -96,7 +96,7 @@ set[AType] collectAndUnlabelRascalTypeParams(set[AProduction] prods) { } @doc{See if a type contains any type parameters.} -bool typeContainsRascalTypeParams(AType t) = size(collectRascalTypeParams(t)) > 0; +bool typeContainsRascalTypeParams(AType t) = /aparameter(_,_) := t; @doc{Return the names of all type variables in the given type.} set[str] typeParamNames(AType t) {