Repository navigation
Interfaces - #1
Merged
Merged
Conversation
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* wire up interface <-> type relationships in Hoist phase so that constructors can take interface args with concrete defaults. implementation validity is enforced in Infer phase. * some unrelated test fixes (de-slopping, avoid User conflict w/ test GraphQL server) Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
There was a problem hiding this comment.
Pull Request Overview
This PR implements comprehensive interface type support for the Dang language, enabling structural subtyping where types can implement interfaces and be used polymorphically. The implementation includes:
- Grammar additions for
interfacedeclarations andimplementsclauses - Subtyping system integrated into Hindley-Milner type inference via
Supertypes()method - Interface validation with GraphQL-spec-compliant covariance/contravariance rules
- Support for both Dang-defined and GraphQL schema interfaces
- Enhanced error messages for type mismatches
Reviewed Changes
Copilot reviewed 67 out of 69 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/hm/unify.go | Refactored unification to support subtyping via Assignable() and isSubtype() functions |
| pkg/hm/types.go | Added Supertypes() method to all types, implementing subtype hierarchy |
| pkg/dang/env.go | Extended Module with interface tracking, validation, and common supertype finding |
| pkg/dang/slots.go | Implemented InterfaceDecl and ClassDecl with interface linking and validation |
| pkg/dang/dang.peg | Added grammar for interface declarations and implements clauses |
| pkg/dang/infer.go | Updated type inference to use Assignable() instead of Unify() |
| tests/* | Comprehensive test coverage for interface functionality and error cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...which was the whole point, but I think the AI shoved a stick into its spokes when it made NonNullType.Types return nil Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
mostly removing no-op/dead code from the initial conversion from chewxy/hm Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Submitting a PR for this as it's pretty large and I'd like to review it myself.
Most of the complexity arises from the fact that supporting interfaces requires proper subtyping:
Catis anAnimal, butAnimalis not aCat. We had to face this previously with null handling -Cat!satisfiesCatbut not vice versa - but to do that I just special-casedNonNullTypeinhm.Unify. For interfaces I'd like to take a more general approach.The general idea is that any type can return a list of supertypes, and during typechecking we'll check against supertypes as well. So
a!hasaas its supertype, andCathasAnimal(among whatever other interfaces it implements).Part of this meant refactoring
hm.Unifyintohm.Assignable(pending rename?) to make it clearly asymmetrical, so that's a big chunk of the changes here.