-
Notifications
You must be signed in to change notification settings - Fork 29
Add type class bounds for T: generics #1226
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
30c4f9d
Add instance declaration syntax for type class bounds
Frotty 1f34789
Add type class bound reading and orphan-rule instance resolution
Frotty 90d87b2
Declare instances with 'implements' instead of a new keyword
Frotty 76c8f02
Resolve type class dispatch on bounded type parameters
Frotty e1dc454
Lower type class dispatch to direct calls
Frotty c046ec7
Validate bounds and inherit instances through nested generics
Frotty 1e642d0
Specialize type class dispatch on the Lua backend
Frotty 89eabb1
Check bounds against the call signature and cover diagnostics with tests
Frotty aa9558b
Document type class bounds
Frotty de966e2
Address review: check instance signatures, abstract bounds and invali…
Frotty 5bc6ee6
Support type class bounds on generic classes
Frotty 0dbce7b
Support bounds inherited from a generic parent, on both targets
Frotty 8c9198d
Retire the Lua limitation on constructing through a fresh generic rec…
Frotty 0db9fa0
Resolve forwarded type arguments when walking supertypes
Frotty 50b8413
Keep the receiver's class binding, and reject two unsupported shapes …
Frotty 2ec9571
Do not read a type argument by position when the arities differ
Frotty 47c3049
Select a type class instance by type identity, not by printed name
Frotty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 generic module declares a bound such as
module M<T: Show>and a class usesM<int>, anyT.show(x)inside the module method is re-resolved in the copied module-instantiation scope;node.lookupType("T")here returns null, so the compiler emitsCould not find variable Tbefore either backend. This makes type-class bounds unusable with existing generic modules; preserve the original bound/type-parameter link or rewrite the type receiver during module expansion.AGENTS.md reference: AGENTS.md:L217-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 addressed in 50b8413, though not by supporting it. The cause is as you say: using a module copies its body into the class and substitutes the module's type parameters in type positions, but a requirement is called on the parameter as an expression, so it survives the copy and no longer resolves.
Supporting it needs either the copy to rewrite those receivers, or type parameters on
ModuleInstanciation, which has none — a parseq change with the matcher fallout that implies. That is more than this change should carry, so bounds on a module type parameter are now rejected with a message that says what is wrong and what to do instead, rather than failing later as an unknown name. Covered byboundOnGenericModule.Worth doing properly as a follow-up: modules are common enough in container code that the combination will come up.