Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 878318e

Browse files
mahgeOpenModelica-Hudson
authored andcommitted
[NF] Fix overload ambiguity with default constrctors for operator records.
Belonging to [master]: - #2241
1 parent c17054f commit 878318e

File tree

2 files changed

+63
-37
lines changed

2 files changed

+63
-37
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -804,14 +804,41 @@ uniontype Call
804804
end if;
805805
return;
806806
else
807-
Error.addSourceMessage(Error.AMBIGUOUS_MATCHING_FUNCTIONS_NFINST,
808-
{typedString(call), candidateFuncListString(list(Util.tuple31(fn) for fn in matchedFunctions),SOME(ov_name))}, info);
809-
fail();
807+
matchedFunctions := resolveOverloadedVsDefaultConstructorAmbigutiy(matchedFunctions);
808+
if listLength(matchedFunctions) == 1 then
809+
(outFunc,args,_) ::_ := matchedFunctions;
810+
return;
811+
else
812+
Error.addSourceMessage(Error.AMBIGUOUS_MATCHING_FUNCTIONS_NFINST,
813+
{typedString(call), candidateFuncListString(list(Util.tuple31(fn) for fn in matchedFunctions),SOME(ov_name))}, info);
814+
fail();
815+
end if;
810816
end if;
811817
end if;
812818

813819
end checkMatchingFunctions;
814820

821+
function resolveOverloadedVsDefaultConstructorAmbigutiy
822+
input list<FunctionMatchKind.MatchedFunction> matchedFunctions;
823+
output list<FunctionMatchKind.MatchedFunction> outMatches;
824+
protected
825+
Function fn;
826+
algorithm
827+
outMatches := {};
828+
// We have at least two exact matches. find the default constructor (if there is one) and remove it from the list
829+
// so that it
830+
// - doesn't cause ambiguities if there is only one other match left OR
831+
// - it doesn't appear in the error messages in the case of more than one overloaded constructor matches.
832+
for mt_fn in matchedFunctions loop
833+
fn := Util.tuple31(mt_fn);
834+
if not stringEqual(Absyn.pathLastIdent(fn.path), "'constructor'.'$default'") then
835+
outMatches := mt_fn::outMatches;
836+
end if;
837+
end for;
838+
839+
outMatches := listReverse(outMatches);
840+
end resolveOverloadedVsDefaultConstructorAmbigutiy;
841+
815842
function typeOf
816843
input Call call;
817844
output Type ty;
@@ -1124,48 +1151,47 @@ protected
11241151
candidates := {};
11251152
matchedFunctions := {};
11261153
if Type.isComplex(Type.arrayElementType(argty)) then
1127-
Type.COMPLEX(cls=recopnode) := argty;
1128-
ErrorExt.setCheckpoint("NFTypeCheck:operatorOverloadDefined");
1129-
try
1130-
fn_ref := Function.lookupFunction(Absyn.CREF_IDENT("'String'",{}), recopnode, InstNode.info(recopnode));
1131-
ErrorExt.delCheckpoint("NFTypeCheck:operatorOverloadDefined");
1132-
else
1133-
ErrorExt.rollBack("NFTypeCheck:operatorOverloadDefined");
1134-
fail();
1135-
end try;
1154+
Type.COMPLEX(cls=recopnode) := argty;
1155+
ErrorExt.setCheckpoint("NFTypeCheck:operatorOverloadDefined");
1156+
try
1157+
fn_ref := Function.lookupFunction(Absyn.CREF_IDENT("'String'",{}), recopnode, InstNode.info(recopnode));
1158+
ErrorExt.delCheckpoint("NFTypeCheck:operatorOverloadDefined");
1159+
else
1160+
ErrorExt.rollBack("NFTypeCheck:operatorOverloadDefined");
1161+
fail();
1162+
end try;
11361163

1137-
fn_ref := Function.instFuncRef(fn_ref, InstNode.info(recopnode));
1164+
fn_ref := Function.instFuncRef(fn_ref, InstNode.info(recopnode));
11381165
candidates := Call.typeCachedFunctions(fn_ref);
1139-
for fn in candidates loop
1140-
TypeCheck.checkValidOperatorOverload("'String'", fn, recopnode);
1141-
end for;
1166+
for fn in candidates loop
1167+
TypeCheck.checkValidOperatorOverload("'String'", fn, recopnode);
1168+
end for;
11421169

11431170
ErrorExt.setCheckpoint("NFCall:typeStringCall");
11441171
matchedFunctions := Function.matchFunctions(candidates, args, named_args, info);
11451172
ErrorExt.rollBack("NFCall:typeStringCall");
11461173

1147-
exactMatches := FunctionMatchKind.getExactMatches(matchedFunctions);
1148-
if listEmpty(exactMatches) then
1149-
Error.addSourceMessage(Error.NO_MATCHING_FUNCTION_FOUND_NFINST,
1150-
{typedString(argtycall), candidateFuncListString(candidates,NONE())}, info);
1151-
fail();
1152-
end if;
1153-
1154-
if listLength(exactMatches) == 1 then
1155-
(operfn,args,_) ::_ := exactMatches;
1156-
outType := Function.returnType(operfn);
1157-
callExp := Expression.CALL(Call.TYPED_CALL(operfn, outType, Variability.CONSTANT, list(Util.tuple31(a) for a in args)
1158-
, CallAttributes.CALL_ATTR(
1159-
outType, false, false, false, false, DAE.NO_INLINE(),DAE.NO_TAIL())
1160-
)
1161-
);
1174+
exactMatches := FunctionMatchKind.getExactMatches(matchedFunctions);
1175+
if listEmpty(exactMatches) then
1176+
Error.addSourceMessage(Error.NO_MATCHING_FUNCTION_FOUND_NFINST,
1177+
{typedString(argtycall), candidateFuncListString(candidates,NONE())}, info);
1178+
fail();
1179+
end if;
11621180

1163-
return;
1164-
else
1165-
Error.addSourceMessage(Error.AMBIGUOUS_MATCHING_FUNCTIONS_NFINST,
1181+
if listLength(exactMatches) == 1 then
1182+
(operfn,args,_) ::_ := exactMatches;
1183+
outType := Function.returnType(operfn);
1184+
callExp := Expression.CALL(Call.TYPED_CALL(operfn, outType, Variability.CONSTANT, list(Util.tuple31(a) for a in args)
1185+
, CallAttributes.CALL_ATTR(
1186+
outType, false, false, false, false, DAE.NO_INLINE(),DAE.NO_TAIL())
1187+
)
1188+
);
1189+
return;
1190+
else
1191+
Error.addSourceMessage(Error.AMBIGUOUS_MATCHING_FUNCTIONS_NFINST,
11661192
{typedString(call), candidateFuncListString(list(Util.tuple31(fn) for fn in matchedFunctions),NONE())}, info);
1167-
fail();
1168-
end if;
1193+
fail();
1194+
end if;
11691195

11701196
end if;
11711197

Compiler/NFFrontEnd/NFFunction.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ uniontype FunctionMatchKind
136136
outFuncs := mf::outFuncs;
137137
end if;
138138
end for;
139-
listReverse(outFuncs);
139+
outFuncs := listReverse(outFuncs);
140140
end getExactMatches;
141141

142142
function isExactMatch

0 commit comments

Comments
 (0)