Skip to content
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

Allow backticks in variables defined through pattern matching #8044

Closed
scabug opened this issue Dec 7, 2013 · 5 comments
Closed

Allow backticks in variables defined through pattern matching #8044

scabug opened this issue Dec 7, 2013 · 5 comments

Comments

@scabug
Copy link

scabug commented Dec 7, 2013

scala> trait HasType{ var `type`: String }
defined trait HasType

Would be nice if that compiled:

scala> new HasType{ var Some(`type`) = Some("foo") }
<console>:10: error: stable identifier required, but $anon.this.`type` found.
              new HasType{ var Some(`type`) = Some("foo") }
                                    ^

Workaround:

scala> new HasType{ var Some(t) = Some("foo"); var `type`= t }
res7: HasType{def t: String; def t_=(x$1: String): Unit} = $anon$1@38c60a18

I am programmatically generating Scala code, so the workaround means a corner case in the code generator.

@scabug
Copy link
Author

scabug commented Dec 7, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8044?orig=1
Reporter: @cvogt

@scabug
Copy link
Author

scabug commented Dec 7, 2013

@cvogt said:
Already has different semantics. Change wouldn't make sense.

@scabug
Copy link
Author

scabug commented Dec 8, 2013

@retronym said:
It might be possible to extend the grammar to allow this in pattern binders:

I think we could change:

Pattern2 ::= varid ‘@’ Pattern3

to:

Pattern2 ::= id ‘@’ Pattern3

Which would admit both of:

scala> val Some(Tpe @ _) = Some(1)
<console>:1: error: ')' expected but '@' found.
       val Some(Tpe @ _) = Some(1)
                    ^

scala> val Some(`type` @ _) = Some(1)
<console>:1: error: ')' expected but '@' found.
       val Some(`type` @ _) = Some(1)
                       ^

Perhaps you can think over this proposal critically. If you can make a case that it doesn't introduce ambiguity, lets discuss at the Scala meeting.

@scabug
Copy link
Author

scabug commented Dec 9, 2013

@cvogt said:
Nice idea! In my case, I worked around it using positional access on tuples for now, getting away without special casing. I re-open the ticket as Improvement/Trivial, so somebody else can pick up the topic if interested.

@scabug
Copy link
Author

scabug commented Jan 31, 2016

@som-snytt said:
This is the narrower change of allowing backquoted idents that still look like varids.

scala/scala#4935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants