Skip to content

Fix type inference bugs and deduplicate canonical_type#5

Merged
undivisible merged 1 commit into
masterfrom
devin/1782093072-fix-review-findings
Jun 22, 2026
Merged

Fix type inference bugs and deduplicate canonical_type#5
undivisible merged 1 commit into
masterfrom
devin/1782093072-fix-review-findings

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

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() on core_ir::Typ. The three call sites (core_ir_verifier, core_typecheck, native_emit/lower) now delegate to it.

2. Fix verifier false positives on Any return types

The verifier used raw equality (canonical_type(&expr_typ) != canonical_type(ret)) which would flag return 42 as a type mismatch in a function declared -> Any. Added Typ::compatible_with() which mirrors core_typecheck's existing type_compatible:

// Before (verifier):
canonical_type(&expr_typ) != canonical_type(ret)  // false positive when ret = Any

// After:
!ret.compatible_with(&expr_typ)  // Any matches everything

3. Fix js_return_type / ruby_return_type: scan nested returns

Both only iterated top-level statements, missing returns inside If/Loop/Match blocks. Extracted shared find_return_expr that recurses into branches.

4. Fix js_return_type Binary op → always Int

Expr::Binary { .. } => Typ::Int was wrong for comparisons (==, <) and logical ops (&&, ||) which should be Bool. Now dispatches by operator.

5. Fix go_return_type greedy DFS

Replaced named_descendant(func, "type_identifier") (searches entire subtree including body) with a direct-child scan that stops at the block node — same pattern as v_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

@undivisible undivisible self-assigned this Jun 22, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

- 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>
@devin-ai-integration devin-ai-integration Bot force-pushed the devin/1782093072-fix-review-findings branch from d651ac1 to 7fb0011 Compare June 22, 2026 02:05
@undivisible undivisible merged commit 826e346 into master Jun 22, 2026
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant