-
Notifications
You must be signed in to change notification settings - Fork 29
Fix duplicate requirements across type class bounds #1228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,12 +98,19 @@ public void addMemberMethods(Element node, String name, List<FuncLink> result) { | |
| if (!staticRef) { | ||
| return; | ||
| } | ||
| // Bounds are ordered, and an earlier one wins: two bounds may require the same operation, | ||
| // and offering both would make every call to it ambiguous rather than simply choosing. | ||
| for (InterfaceDef bound : TypeClassConstraints.boundInterfaces(def)) { | ||
| boolean found = false; | ||
| for (FuncDef method : bound.getMethods()) { | ||
| if (method.getName().equals(name)) { | ||
| result.add(requirementLink(node, bound, method)); | ||
| found = true; | ||
| } | ||
| } | ||
| if (found) { | ||
| return; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an earlier bound declares AGENTS.md reference: AGENTS.md:L62-L64 Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, and it was a regression from my own fix in this PR — I applied the preference by name, which is too coarse. Fixed in 4124bb8. Earlier bounds now win only where the requirements have the same shape, which is the case where offering both really would make every call ambiguous. Candidates are gathered from every bound and a later one is dropped only when an earlier bound already supplied the same parameter types, so a differently shaped overload stays available and overload resolution chooses between them as usual. Regression test |
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a bounded generic function or class method is declared but never called, its owner has no row in
specializedFunctions, so this throws even though the dispatch is unreachable;settleRemainingDispatches()runs beforeoptimizer.removeGarbage(), which would otherwise delete that function. I reproduced this with an unusedfunction unused<Q: Show>(Q x) returns stringduring Lua compilation: the parent revision accepts it, while this change reports that the concrete type is unavailable. Determine reachability or remove garbage before rejecting unresolved dispatches so unused generic APIs remain valid on Lua as they are on Jass.AGENTS.md reference: AGENTS.md:L215-L221
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and fixed in 13eb5f5, another regression from this PR rather than a pre-existing one. Declaring a bounded generic and never calling it is entirely reasonable, and my settle pass rejected it because it could not distinguish unreachable from unresolvable.
Rather than compute reachability there, I stopped deciding it. The pass now only neutralises dispatches it can prove dead, which is those in a function that does have a specialization, since every reachable call was rewritten to it. Everything else is left to the passes that already decide reachability, and garbage removal deletes the unused generic as before.
A dispatch which survives that far and reaches the Lua backend is now reported there rather than failing as an unimplemented case. That is the point where it is known to be both reachable and unresolvable, so the message is worth something.
Tests:
unusedBoundedGenericFunctionLuais your repro; I addedunusedBoundedGenericClassLuaandunusedBoundedGenericFunctionalongside it, since an unused generic class and the Jass path are the neighbouring cases and my last two fixes here were both too narrow.