-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix incorrect warning on type ascription for backquoted identifiers #23088
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One note on how the feature should work, if it is a feature.
@@ -3177,7 +3177,7 @@ object Parsers { | |||
def pattern1(location: Location = Location.InPattern): Tree = | |||
val p = pattern2(location) | |||
if in.isColon then | |||
val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf[Number] | |||
val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf[Number] || isBackquoted(p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scala 2 honors the requirement even in backquoting.
scala> 42 match { case `Int`: Int => `Int` }
^
error: Pattern variables must start with a lower-case letter. (SLS 8.1.1.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normal syntax for non-var: 42 match { case X @ (_: Int) => X }
Maybe it's worth adding a neg test.
tests/pos/i22989.scala
Outdated
@@ -0,0 +1,3 @@ | |||
//> using options -Xfatal-warnings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//> using options -Xfatal-warnings | |
//> using options -Werror |
tests/pos/i15784.scala
Outdated
|
||
def i15784_auxiliary = 42 match | ||
case `type` : Int => `type` | ||
case _ => ??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could quiet the other warnings and add the -Werror
in the existing file. These directories get large.
By quiet, I'd suggest a def for each "rest" test. (and not just nowarn.)
Thanks for the review! |
…n patterns address reviews minor fix
|
||
def case3 = 42 match | ||
case `Int`: Int => `Int` // warn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the test rig checks the // warn
in a neg test, but of course it's verified by the check file. (I'm wondering if the test rig should do that, as an enhancement. I know a difference is that it's OK to have zero warns in a warn test but not OK to have zero errors in a neg test.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, would it be better if I make a separate tests/warn/i15784.scala
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think it's fine. Maybe with -Werror
you can mark them error. But I was just musing aloud, in case I read this again later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I wouldn't have guessed unsplice
.
As linked above, I got a bonus Scala 2 ticket out of it. |
closes #22989