Skip to content

Check ascription in valdef pattern#25597

Open
som-snytt wants to merge 1 commit intoscala:mainfrom
som-snytt:issue/25595
Open

Check ascription in valdef pattern#25597
som-snytt wants to merge 1 commit intoscala:mainfrom
som-snytt:issue/25595

Conversation

@som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Mar 21, 2026

Fixes #25595

At pattern1 and varDefOrDcl (which uses pattern2), check that the optional ascription is legal. Accept arbitrary identifiers in pattern definitions case id: T, which is already the case for the equivalent case id @ (_: T).

Correct the camelcase spelling of Elsewhere.

@som-snytt
Copy link
Contributor Author

The breakage was due to "variable pattern" in a typed pattern versus "define X" in a valdef.

This appears simple, but currently it incorrectly accepts case X: String => instead of erroring that pattern variables must begin with lowercase. The correct syntax is case X @ (_: String) =>.

As a digression, maybe it should just officially accept case X: String that looks like val X: String. (In any other position in a pattern, it would distinguish variable ids from constant ids.) (The two forms already treat backquoted idents uniformly!)

I would have liked to add a new message with a non-trivial explanation, but the energy hump for introducing an error ID is much too high.

@som-snytt som-snytt changed the title Also check ascription in valdef pattern Check ascription in valdef pattern Mar 23, 2026
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.

Fancy type ascription to pattern should also warn in valdef

1 participant