Say which part of a function signature does not match - #331
Merged
Merged
Conversation
Assigning a function to a function type it does not match reported only the
two types:
() => s32 is not matching type () => number
invalid cast from () => s32 to string | () => number
Neither says what is wrong, and the second names the whole union rather than
the member that was meant. The return type is the usual reason: an integer
literal is s32 here, so `function one() { return 1; }` is `() => s32` and
does not match `() => number`.
emitFunctionTypeMismatch now names the part that differs - argument count,
argument position, or return type - and for a return type points at
declaring it:
can't assign '() => s32' to '() => number': return type 's32' is not
'number'. Declare the return type to get one, for example
'function f(): number'
A function assigned to a union reports against the union's function member
instead of the union.
Diagnostics only: what compiles and what does not is unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
Assigning a function to a function type it does not match reported only the two types:
Neither says what is wrong, and the second names the whole union rather than the function member that was meant.
The return type is the usual reason, and it is easy to hit by accident: an integer literal is
s32in this language (let x = 1; x = 2.5keeps2), sofunction one() { return 1; }is() => s32and does not match() => number— as a plain assignment, a function argument, an arrow function, or a union member.Change
emitFunctionTypeMismatchnames the part of the signature that differs — argument count, argument position, or return type — and for a return type points at declaring it:A function assigned to a union is now reported against the union's function member rather than the union as a whole.
This is diagnostics only: what compiles and what does not is unchanged. The alternative — a generated wrapper that casts the result, so
() => s32would be assignable to() => number— was considered and not taken; declaring the return type is the answer here.Tests
No test is added: the repository has no mechanism for asserting compiler error text, and this change alters no accepted or rejected program.
Full Windows debug suite (
ctest -R "^test-|^unittest-"): 2759/2759 passed.🤖 Generated with Claude Code