Details

      Description

      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
      

        Activity

        Hide
        Eugene Burmako added a comment -

        Same for $null, and nonsense like $yield or $extends.

        Show
        Eugene Burmako added a comment - Same for $null, and nonsense like $yield or $extends.
        Hide
        Jason Zaugg added a comment -

        Also works:

        class C { s"${this}" }
        
        Show
        Jason Zaugg added a comment - Also works: class C { s"${this}" }
        Hide
        Dominik Gruntz added a comment -

        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
        

        ?

        Show
        Dominik Gruntz added a comment - 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 ?
        Hide
        Jason Zaugg added a comment -

        Requiring braces for backquoted idents isn't so onerous, IMO.

        Show
        Jason Zaugg added a comment - Requiring braces for backquoted idents isn't so onerous, IMO.
        Hide
        Dominik Gruntz added a comment -

        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?

        Show
        Dominik Gruntz added a comment - 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?
        Hide
        Jason Zaugg added a comment -

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

        Show
        Jason Zaugg added a comment - Actually, I would just leave it as is and require the use of braces. If I had to allow one, it would be $this .
        Hide
        Dominik Gruntz added a comment -

        https://github.com/scala/scala/pull/927
        I have enabled $this (as a special case).

        Show
        Dominik Gruntz added a comment - https://github.com/scala/scala/pull/927 I have enabled $this (as a special case).
        Hide
        Dominik Gruntz added a comment -
        Show
        Dominik Gruntz added a comment - fixed with https://github.com/scala/scala/pull/927 .

          People

          • Assignee:
            Dominik Gruntz
            Reporter:
            Eugene Burmako
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development