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

Cannot use $this in string interpolation #5856

Closed
scabug opened this issue May 31, 2012 · 9 comments
Closed

Cannot use $this in string interpolation #5856

scabug opened this issue May 31, 2012 · 9 comments

Comments

@scabug
Copy link

scabug commented May 31, 2012

scala> class C { s"$this" }
<console>:7: error: not found: value this
       class C { s"$this" }
                    ^

scala> class C { val q = this; s"$q" }
defined class C
@scabug
Copy link
Author

scabug commented May 31, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5856?orig=1
Reporter: @xeno-by
Affected Versions: 2.10.0-M3
Other Milestones: 2.10.0-M6

@scabug
Copy link
Author

scabug commented May 31, 2012

@xeno-by said:
Same for $null, and nonsense like $yield or $extends.

@scabug
Copy link
Author

scabug commented Jul 10, 2012

@retronym said:
Also works:

class C { s"${this}" }

@scabug
Copy link
Author

scabug commented Jul 12, 2012

@dgruntz said:
should $yield and $extends not be allowed? Consider

scala> val `yield` = 1
yield: Int = 1

scala> val `extends` = 2
extends: Int = 2

scala> s"$yield / $extends"
res23: String = 1 / 2

Or do you expect that one should have to write

scala> s"$`yield`"
<console>:1: error: invalid string interpolation
       s"$`yield`"

(which currently issues an error message), as in

scala> s"${`yield` + `extends`}"
res24: String = 3

?

@scabug
Copy link
Author

scabug commented Jul 12, 2012

@retronym said:
Requiring braces for backquoted idents isn't so onerous, IMO.

@scabug
Copy link
Author

scabug commented Jul 15, 2012

@dgruntz said:
I am about to fix this bug. I have resolved the problem of keywords and literals like null, false and true. After having read the SIP-11 again, I have also decided not to support backquoted identifiers (but they can still be written in a block).

The final question I have is whether to support $this or not. SIP-11 specifies the simpler escape sequence as the $-sign followed by an identifier consisting only of alphanumeric characters, and that $id is equivalent to ${id}. Strictly speaking, this is not an identifier, but probably it might be useful to write $this in an interpolated string. What is your expectation?

@scabug
Copy link
Author

scabug commented Jul 16, 2012

@retronym said:
Actually, I would just leave it as is and require the use of braces. If I had to allow one, it would be $this.

@scabug
Copy link
Author

scabug commented Jul 17, 2012

@dgruntz said:
scala/scala#927
I have enabled $this (as a special case).

@scabug
Copy link
Author

scabug commented Aug 7, 2012

@dgruntz said:
fixed with scala/scala#927.

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