Skip to content

Commit 4cfde99

Browse files
committed
Show expected params on no method match
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
1 parent 0114b28 commit 4cfde99

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public FunctionHeader(TypeID returnType, TypeID... parameterTypes) {
4848
this.thrownType = null;
4949

5050
for (int i = 0; i < parameterTypes.length; i++)
51-
parameters[i] = new FunctionParameter(parameterTypes[i], null);
51+
parameters[i] = new FunctionParameter(parameterTypes[i], "param" + i);
5252

5353
minParameters = parameterTypes.length;
5454
maxParameters = parameterTypes.length;

CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/CompileErrors.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.openzen.zenscript.codemodel.OperatorType;
77
import org.openzen.zenscript.codemodel.identifiers.MethodID;
88
import org.openzen.zenscript.codemodel.identifiers.instances.MethodInstance;
9+
import org.openzen.zenscript.codemodel.type.BasicTypeID;
910
import org.openzen.zenscript.codemodel.type.TypeID;
1011

1112
import java.util.List;
@@ -255,13 +256,17 @@ public static CompileError ambiguousCall(List<FunctionHeader> candidates) {
255256
return new CompileError(CompileExceptionCode.CALL_AMBIGUOUS, message.toString());
256257
}
257258

258-
public static CompileError noMethodMatched(List<FunctionHeader> candidates) {
259+
public static CompileError noMethodMatched(List<FunctionHeader> candidates, List<TypeID> argumentTypes) {
260+
FunctionHeader expectedHeader = new FunctionHeader(BasicTypeID.UNDETERMINED, argumentTypes.toArray(TypeID.NONE));
261+
259262
StringBuilder message = new StringBuilder("Method invocation invalid, none of these overloads match:");
260263
for (FunctionHeader header : candidates) {
261-
message.append("\n").append(header.toString());
262-
// for (FunctionHeader candidate : candidateFunctions)
263-
// explanation.append(candidate.explainWhyIncompatible(scope, arguments)).append("\n");
264+
message.append("\n - ").append(header.toString());
264265
}
266+
message.append("\nTarget overload should be compatible with header ").append(expectedHeader);
267+
// TODO("Reimplement this once we are in a better place for it")
268+
// for (FunctionHeader candidate : candidateFunctions)
269+
// explanation.append(candidate.explainWhyIncompatible(scope, arguments)).append("\n");
265270
return new CompileError(CompileExceptionCode.CALL_NO_VALID_METHOD, message.toString());
266271
}
267272

CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/MatchedCallArguments.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public static <T extends AnyMethod> MatchedCallArguments<T> match(
4242
}
4343
}
4444

45-
return new MatchedCallArguments<>(CompileErrors.noMethodMatched(overloads.stream()
46-
.map(AnyMethod::getHeader)
47-
.collect(Collectors.toList())));
45+
List<FunctionHeader> headers = overloads.stream().map(AnyMethod::getHeader).collect(Collectors.toList());
46+
List<TypeID> types = Arrays.stream(arguments).map(CompilingExpression::eval).map(it -> it.type).collect(Collectors.toList());
47+
return new MatchedCallArguments<>(CompileErrors.noMethodMatched(headers, types));
4848
}
4949

5050
private static <T extends AnyMethod> MatchedCallArguments<T> ambiguousCall(Map<CastedExpression.Level, List<MatchedCallArguments<T>>> methodsGroupedByMatchLevel) {

0 commit comments

Comments
 (0)