Fix type inference bugs and deduplicate canonical_type#5
Merged
Conversation
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Move canonical_type to Typ::canonical() on core_ir::Typ, eliminating 3
identical copies across core_ir_verifier, core_typecheck, native_emit/lower
- Add Typ::is_any() and Typ::compatible_with() for proper Any-type wildcard
handling; fix verifier false positives on Named("Any") return types
- Fix js_return_type and ruby_return_type to scan nested returns inside
If/Loop/Match blocks, not just top-level statements
- Fix js_return_type Binary op inference: comparison/logical ops now map to
Bool instead of Int
- Fix go_return_type: replace greedy named_descendant DFS with direct-child
scan between params and body, preventing false matches on body-internal types
- Fix zig_body empty check: handle whitespace inside braces instead of strict
"{}" string equality
- Fix ruby_methods_extract_scalar_bodies test expectation (was stale after
ruby_return_type was added)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
d651ac1 to
7fb0011
Compare
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.
Summary
Fixes several bugs found during code review of recent polyglot type-inference commits:
1. Deduplicate
canonical_type(3× copy-paste → 1 method)Moves the logic to
Typ::canonical()oncore_ir::Typ. The three call sites (core_ir_verifier,core_typecheck,native_emit/lower) now delegate to it.2. Fix verifier false positives on
Anyreturn typesThe verifier used raw equality (
canonical_type(&expr_typ) != canonical_type(ret)) which would flagreturn 42as a type mismatch in a function declared-> Any. AddedTyp::compatible_with()which mirrorscore_typecheck's existingtype_compatible:3. Fix
js_return_type/ruby_return_type: scan nested returnsBoth only iterated top-level statements, missing returns inside
If/Loop/Matchblocks. Extracted sharedfind_return_exprthat recurses into branches.4. Fix
js_return_typeBinary op → alwaysIntExpr::Binary { .. } => Typ::Intwas wrong for comparisons (==,<) and logical ops (&&,||) which should beBool. Now dispatches by operator.5. Fix
go_return_typegreedy DFSReplaced
named_descendant(func, "type_identifier")(searches entire subtree including body) with a direct-child scan that stops at the block node — same pattern asv_return_type.6. Fix Zig empty body check
node_txt(src, body).trim() == "{}"failed on{ }or{\n}. Now strips outer braces and checks if inner content is whitespace-only.Link to Devin session: https://app.devin.ai/sessions/5d1e59069bb447cd8597fb4a8c6c09ea
Requested by: @undivisible