Skip to content

Fix #10050: Use lowercase pattern variable syntax for quoted patterns #10125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2020

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Oct 30, 2020

Use lower cases for quoted type patterns

case '{ $x: T } => '{ val y: T = .. .} // T from outside
case '{ $x: t } => '{ val y: t = .. .} // t form within the quotes
case '{ type t; $x: Map[`t`, `t`] } => '{ val y: t = .. .} // t form within the quotes
case '{ $x: `t` } => '{ val y: t = .. .} // t from outside

Based on #10050 (comment)

@nicolasstucki nicolasstucki self-assigned this Oct 30, 2020
@nicolasstucki nicolasstucki force-pushed the fix-#10050 branch 6 times, most recently from 1089a03 to a65bdc8 Compare November 2, 2020 13:55
@smarter
Copy link
Member

smarter commented Nov 2, 2020

case '{ type t; $x: Map[`t`, `t`] } => '{ val y: t = .. .} // t form within the quotes

Would the following be possible?

case '{ $x: Map[t, t] } => '{ val y: t = .. .} // t form within the quotes

Semantically this makes sense I think: we accept a type in all these positions, it's just that it has to be the same one. Normal pattern syntax does not currently allow referring to the same pattern variable multiple times in a pattern, but I recall @LPTK had some ideas on how this could be useful (e.g., when using alternatives).

@nicolasstucki
Copy link
Contributor Author

@smarter in theory it is possible. It is the next step that I want to try. The change needed to support this is unrelated to the change in syntax and I would add it in another PR.

@LPTK
Copy link
Contributor

LPTK commented Nov 2, 2020

It would be great if the change made to allow repeating type pattern variables would be extended to all patterns, not just quoted patterns.

As for supporting term pattern variables in pattern alternatives, that's a whole other beast!

@nicolasstucki nicolasstucki marked this pull request as ready for review November 2, 2020 16:17
@nicolasstucki nicolasstucki changed the title Fix #10050: Use lower pattern variable syntax for quoted patterns Fix #10050: Use lowercase pattern variable syntax for quoted patterns Nov 2, 2020
@nicolasstucki nicolasstucki added this to the 3.0.0-M2 milestone Nov 4, 2020
@nicolasstucki nicolasstucki force-pushed the fix-#10050 branch 5 times, most recently from 6a4f5fa to daaa2d1 Compare November 6, 2020 16:11
@nicolasstucki nicolasstucki requested review from smarter and removed request for liufengyun November 8, 2020 18:53
@nicolasstucki nicolasstucki assigned smarter and unassigned liufengyun Nov 8, 2020
In quoted pattern
* Identify names lowered case names as type holes
  * `case '{ $x: t }`: `t` is type from within the expression
  * `case '{ $x: T }`/```case '{ $x: `t`}```: `T`/`t` type from outside the pattern
* Old `$` prefixed syntax emits an error describing to new syntax
@nicolasstucki
Copy link
Contributor Author

Rebased and resolved conflicts

@nicolasstucki nicolasstucki merged commit 3e30786 into scala:master Nov 9, 2020
@nicolasstucki nicolasstucki deleted the fix-#10050 branch November 9, 2020 15:28
@Kordyjan Kordyjan modified the milestones: 3.0.0-M2, 3.0.0 Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants