Repository navigation
Report an undeclared type as undeclared, not as a type failing to match itself - #571
Merged
Merged
Conversation
…ch itself
let p: Point = Point { x: 3, y: 4 } # no Point in scope
gave:
Variable 'p' initialized with Point but annotated as Point
A SemanticType renders by its name. The struct literal produced
STRUCT(name='Point') and the annotation, naming nothing in scope, produced
UNKNOWN(name='Point'), so both sides printed the same string and the message
described a type as failing to match itself. It now reads:
Variable 'p' is annotated with unknown type 'Point', which is not
declared in this scope
The same shape existed for return types, where `-> Widget` with no Widget
declared gave "returns Widget but should return Widget".
What the checker accepts is unchanged. Both programs were already rejected,
correctly, since the annotation names nothing; only the message was wrong.
A mismatch between two declared types keeps the original wording.
Found by running the documentation examples: six blocks across
docs/book/, docs/library/dynamics.md and docs/language/ failed this way.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Merged
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.
The message
gave:
A
SemanticTyperenders by its name. The struct literal producedSTRUCT(name='Point')and the annotation, naming nothing in scope, producedUNKNOWN(name='Point'), so both sides printed the same string and the message described a type as failing to match itself. That reads like a compiler malfunction rather than a missing declaration.It now reads:
The same shape existed for return types:
-> Widgetwith noWidgetdeclared gavereturns Widget but should return Widget.Scope
What the checker accepts is unchanged. Both programs were already rejected, correctly, since the annotation names nothing. Only the message was wrong. A mismatch between two declared types keeps the original wording:
How it was found
Running the documentation examples. Six blocks failed this way, across
docs/book/06-pipelines-and-results.md,docs/book/09-expressions-and-matching.md,docs/book/10-memory-and-lifetimes.md,docs/library/dynamics.mdanddocs/language/types.md. Each is a fragment that names a type declared elsewhere in the page, so each produced a message about a type not matching itself.Verification
pytest tests/ruff check srcFive new tests in
tests/unit/test_unknown_type_diagnostic.pycover the variable case, the return-type case, that a real mismatch between declared types keeps its original wording, and that a correctly declared struct still assigns cleanly.