Perhaps I did not explain clearly, or perhaps I misunderstand the existing process. My understanding is:
1. For each function call in an expression, we currently look for functions with the correct name, starting in the local scope. If no function with that name is found in the local scope, then we look in the next-higher enclosing scope, and so forth.
2. As soon as we reach a scope with at least one function having the correct name, we take all functions in that scope with the correct name as our candidates for that call. We then stop looking for candidates. If no candidates are found in any scope, we raise an error.
3. Then, after repeating the above process for all function calls in the expression, we attempt to solve for valid combinations of types and functions from among our candidates. If no solutions are found, we raise an error. Otherwise, we rank the solutions. If there is exactly one top-ranked solution, we use it. Otherwise we raise an ambiguity error.
Is this reasonably close to correct?
If so, my idea is:
Do everything exactly as above, except if no valid solutions are found in paragraph 3 then, instead of raising an error, repeat the scope-widening process for all function calls in the expression all the way to global scope. If at least one new candidate was found, then repeat the solving process and continue from there.
• • •
As you can see, the process stays exactly the same as it currently is, *except* in the case where no valid solutions were found in paragraph 3. In that case, there is currently a compiler error. And it is exactly and exclusively there that I am saying we could do some extra work to look for more candidates.
Thus I claim, for expressions which currently compile, everything will work exactly as it does today, with no extra compilation time. The only change is in certain cases which *don’t* compile today: *after* the existing attempt to solve them fails, *then* go back and look for more candidates and try again.
There may be other problems with this approach, possibly involving how to rank solutions using candidates from different scopes. But taking more time to compile code which already compiles is not one of them.