public Operation resolveInvocation(FileScope scope, SyntaxNode where, String name, Signature s) { LinkedHashMap<Signature, LinkedList<Operation>> funcs = methods.get(name); if (funcs == null) return null; // No signature specified? Only one method with the name allowed if (s == null) { if (funcs.size() > 1) throw Problem.ofType(ProblemId.AMBIGUOUS_METHOD_ACCESS) .at(where) .details("method", name, assembleFuncList(funcs)) .raiseUnrecoverable(); return chooseFunctionForInvocation(funcs.entrySet().iterator().next().getValue(), scope); } LinkedList<Operation> funcList = funcs.get(s); if (funcList == null) { // No direct hit :( Operation globalCandidate = null; Operation candidate = null; boolean error = false; for (Signature sig : funcs.keySet()) { if (s.canImplicitCastTo(sig)) { funcList = funcs.get(sig); candidate = chooseFunctionForInvocation(funcList, scope); if (candidate != null && globalCandidate != null) { error = true; } globalCandidate = candidate; } if (error) throw Problem.ofType(ProblemId.AMBIGUOUS_METHOD_CALL) .at(where) .details( "method", candidate.getNameAndSignature(), globalCandidate.getNameAndSignature()) .raiseUnrecoverable(); globalCandidate = candidate; } return globalCandidate; } // Direct signature hit! return chooseFunctionForInvocation(funcList, scope); }