Skip to content

Type checker: wire up @expect directive suppression for type/dnu warnings#1015

Merged
jamesc merged 5 commits intomainfrom
worktree-chore/type-warns-in-compile
Feb 28, 2026
Merged

Type checker: wire up @expect directive suppression for type/dnu warnings#1015
jamesc merged 5 commits intomainfrom
worktree-chore/type-warns-in-compile

Conversation

@jamesc
Copy link
Owner

@jamesc jamesc commented Feb 28, 2026

Summary

  • Wire up @expect dnu and @expect type suppression in the type checker so @expect directives properly suppress type-checker diagnostics
  • Tag 5 previously-uncategorised type checker diagnostics with DiagnosticCategory::Type so @expect type can match them
  • Add infer_stmts helper that skips ExpectDirective AST nodes during body iteration (prevents them from clobbering return-type inference)
  • Add @expect dnu annotations to Collection.bt collect: and select: methods to suppress false "Object does not understand 'withAll:'" warnings from the species pattern

Context

self species withAll: result returns the receiver's metaclass at runtime — inherently dynamic, cannot be type-checked statically. The species method returns -> Object, but the actual class at runtime will understand withAll:. The @expect dnu directive suppresses this known-safe warning.

Test plan

  • just test — all Rust tests pass (including 3 new @expect integration tests)
  • just build — stdlib builds cleanly, no more withAll: warnings
  • just test-stdlib — all tests pass
  • just clippy — clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • More consistent and accurate type-checking diagnostics and severity for parameter/return/field warnings.
    • @expect suppression correctly applies only to the immediate following expression.
  • Refactor

    • Centralized statement inference to simplify and standardize body and block type-checking.
  • Documentation

    • Clarifying annotations added to collection operations about species/return-type behavior (no runtime changes).
  • Tests

    • Added tests covering @expect behavior, type warnings, and selector compatibility.

…nings

`species` returns the receiver's metaclass at runtime, which is inherently
dynamic. Declaring `-> Object` caused spurious "Object does not understand
'withAll:'" warnings at every callsite using the species pattern (e.g.
Collection#collect:, Collection#select:).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e54fc44 and ed9a80f.

📒 Files selected for processing (1)
  • stdlib/src/Collection.bt

📝 Walkthrough

Walkthrough

Centralizes statement-sequence type inference into a new infer_stmts helper that skips @expect directives and returns the last expression type (or Dynamic for empty lists); replaces per-body loops with calls to this helper, standardizes several type diagnostics to DiagnosticCategory::Type, and adds tests/helpers for @expect behavior.

Changes

Cohort / File(s) Summary
Type checker core
crates/beamtalk-core/src/semantic_analysis/type_checker.rs
Add infer_stmts to infer types for sequences of ExpressionStatement, skip @expect directives, and use its return value for body/return-type checks; replace multiple inline loops (module top-level, method bodies, blocks) with calls to the helper; adjust related control flow.
Diagnostics & tests
crates/beamtalk-core/src/..., crates/beamtalk-core/tests/...
Replace several warning constructions to attach DiagnosticCategory::Type; add helpers to lex/parse and run diagnostics with apply_expect_directives; add tests verifying @expect suppression semantics and scoping.
Stdlib annotations
stdlib/src/Collection.bt
Add @expect dnu directives and explanatory comments to collect: and select: implementations (non-functional annotation/comment changes only).

Sequence Diagram(s)

mermaid
sequenceDiagram
participant AST as AST (statements)
participant TypeChk as TypeChecker::infer_stmts
participant Expect as ExpectDirectiveHandler
participant Diag as Diagnostics

AST->>TypeChk: provide sequence of ExpressionStatement
TypeChk->>Expect: detect & skip `@expect` directives
Note right of TypeChk: infer types for non-directive expressions
TypeChk->>Diag: emit warnings/errors with Type category
TypeChk-->>AST: return last expression type (or Dynamic)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main changes: adding @expect directive suppression for type and DNU warnings in the type checker. The changes include wiring up suppression logic and extending diagnostic construction with DiagnosticCategory::Type across multiple warning types.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch worktree-chore/type-warns-in-compile

Comment @coderabbitai help to get the list of available commands and usage tips.

jamesc and others added 3 commits February 28, 2026 22:02
`@expect dnu` and `@expect type` were already parsed into AST nodes and
handled by `apply_expect_directives` in diagnostic_provider, but the type
checker had no knowledge of them — `ExpectDirective` nodes reset the
inferred body type to Dynamic, breaking return-type inference.

Changes:
- Add `infer_stmts` helper that skips `ExpectDirective` nodes so they
  don't clobber the inferred body type used for return-type checking
- Replace all three method-body loops and the block-body loop with `infer_stmts`
- Tag all previously-uncategorised type checker diagnostics with
  `DiagnosticCategory::Type` so `@expect type` can suppress them
- Remove the `species` special-case (hack) added in the previous commit —
  the right fix is `@expect dnu` at the two callsites in Collection.bt
- Add `@expect dnu` before `self species withAll: result` in `collect:`
  and `select:` — suppression is validated at build time (stale @expect
  is a compile error)
- Add integration tests that go through the full pipeline
  (type checker + `apply_expect_directives`)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
stdlib/src/Collection.bt (1)

140-141: Consider adding a brief comment for consistency.

The @expect dnu in collect: (line 124) has an explanatory comment while this one doesn't. A one-line comment like // species withAll: — see collect: for rationale would help future readers.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@stdlib/src/Collection.bt` around lines 140 - 141, Add a one-line explanatory
comment above the "@expect dnu" in the species-withAll code path to match
collect:'s style; for example, add "// species withAll: — see collect: for
rationale" immediately before the "@expect dnu" that precedes "self species
withAll: result" so future readers know the rationale and can find the related
explanation in collect:.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@stdlib/src/Collection.bt`:
- Around line 140-141: Add a one-line explanatory comment above the "@expect
dnu" in the species-withAll code path to match collect:'s style; for example,
add "// species withAll: — see collect: for rationale" immediately before the
"@expect dnu" that precedes "self species withAll: result" so future readers
know the rationale and can find the related explanation in collect:.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8a75539 and e54fc44.

📒 Files selected for processing (2)
  • crates/beamtalk-core/src/semantic_analysis/type_checker.rs
  • stdlib/src/Collection.bt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jamesc jamesc changed the title Type checker: treat species return as Dynamic Type checker: wire up @expect directive suppression for type/dnu warnings Feb 28, 2026
@jamesc jamesc merged commit 6140f27 into main Feb 28, 2026
8 of 9 checks passed
@jamesc jamesc deleted the worktree-chore/type-warns-in-compile branch February 28, 2026 22:28
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