Skip to content

Conversation

@rtfeldman
Copy link
Contributor

Summary

This PR fixes a bug where static dispatch syntax (e.g., lst.repeat(3)) allowed calling methods whose first parameter type doesn't match the receiver type. Specifically, List.repeat : a, U64 -> List(a) could be called on a List even though its first parameter is a generic a that doesn't specifically accept List values.

  • Added validation during deferred static dispatch constraint resolution to check the method's original first parameter type before instantiation
  • For builtin methods, if the first parameter is an unconstrained rigid type variable (from an explicit annotation), the call is now rejected with a MISSING METHOD error
  • Valid cases still work: first param is the nominal type, first param has constraints, or first param is inferred (flex)
  • Added snapshot test for the bug reproduction case
  • Updated existing snapshot test that now correctly reports additional MISSING METHOD error

Fixes #9019

Co-authored by Claude Opus 4.5

… param

When calling a method via static dispatch syntax (e.g., `lst.repeat(3)`),
the compiler should verify that the method's first parameter type is
compatible with the receiver type. Previously, methods like
`List.repeat : a, U64 -> List(a)` could be called via `lst.repeat(3)`
where `lst : List(b)`, even though `repeat` has a generic first parameter
`a` that doesn't specifically accept List values.

This fix adds a check during deferred static dispatch constraint resolution
that validates the method's ORIGINAL first parameter type (before
instantiation). For builtin methods, if the first parameter is an
unconstrained rigid type variable (from an explicit annotation), the call
is rejected with a MISSING METHOD error.

Valid cases still work:
- First param is the nominal type itself (e.g., `len : List(_) -> U64`)
- First param is a constrained type variable (e.g., `a where [a.method]`)
- First param is inferred (flex) from a lambda without annotation

Fixes #9019

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

Static dispatch incorrectly allows functions without dispatched type as first parameter

2 participants