checker: reject unresolved types used in interface match/is branches - #27694
checker: reject unresolved types used in interface match/is branches#27694rilaaax wants to merge 5 commits into
match/is branches#27694Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 207abfa224
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
1ebba3a to
d85f921
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d85f921627
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
d85f921 to
f1c1a6e
Compare
|
The direct unresolved type case is fixed. To address the second Codex review, the checker still needs to reject unresolved placeholders inside generic instantiations, such as Thanks! |
f1c1a6e to
0df3526
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c80b3b2c37
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
One Codex point is still only partially fixed. I reproduced it on a clean checkout: Thanks! |
fe6bf7b to
86dcad0
Compare
Fixes #26972
Problem
Matching on an interface value with a branch type that was never actually declared (e.g. a typo, or a leftover/renamed type) compiles without any V error, but crashes the underlying C compiler with a confusing error instead:
Minimal repro:
Cause
The parser registers an unresolved type name like
Nilas a.placeholdertype symbol (the normal mechanism used to support forward references). The checker is supposed to reject any.placeholderthat's still unresolved by the time it's actually used, buttype_implements_with_mut_receiver()inchecker.vnever checked for this. It validates a type against an interface by iterating over the interface's required methods/fields; for an interface with few or none of those (e.g. an emptyinterface Value {}), the loop does nothing and the function returnstrueby default — regardless of whether the type it was given actually exists. The bogus placeholder type then flows unchecked into cgen, which generates casts and variant-index machinery for a struct that was never defined, and onlycccatches it.Fix
checker.v:type_implements_with_mut_receiver()now returnsfalseimmediately when given a.placeholdertype, without erroring itself (some callers already have their own dedicated handling for this case).match.v: the interface branch ofmatch_exprs()now reportsunknown type '<name>'when the branch type doesn't implement the interface and is unresolved, mirroring the existing sum type variant error.infix.v: theis/asinterface check is skipped when the type is a placeholder, since that case is already reported a few lines above, avoiding a duplicate error message.Test
Regression test added.