Scala Programming Language
  1. Scala Programming Language
  2. SI-5130

OuterClass.this.type loses type refinement

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.0, Scala 2.9.1
    • Fix Version/s: Scala 2.10.1
    • Component/s: Misc Compiler
    • Labels:
    • Environment:

      Tested on 2.9.0.1 (Ubuntu distr.) and built from trunk. Both interpreter and compiler show the behaviour.

      Description

      scala> class A {
           |   this_a =>
           |   def b= new B
           |   class B {
           |     def a: this_a.type= this_a
           |   }
           | }
      defined class A
      
      scala> def a= new A {
           |   def c { }
           | }
      a: A{def c: Unit}
      
      scala> a.b.a.c
      <console>:10: error: value c is not a member of A
             a.b.a.c
                   ^
      

      Checking the type of a.b.a shows why:

      scala> a.b.a
      res1: A = $anon$1@fe210a
      

      Should be A

      {def c: Unit}

      Surprisingly, changing the "def a" into a "val" works around the issue in this particular case:

      scala> val a= new A {
           |   def c { }
           | }
      a: A{def c: Unit} = $anon$1@2f0bd7
      
      scala> a.b.a
      res3: a.type = $anon$1@2f0bd7
      
      scala> a.b.a.c
      

        Activity

        Hide
        Martin Odersky added a comment -

        It seems that pullrequest has been superseded with something else. Can you point me to the proposed fix again? Sorry for dropping the ball here.

        Show
        Martin Odersky added a comment - It seems that pullrequest has been superseded with something else. Can you point me to the proposed fix again? Sorry for dropping the ball here.
        Hide
        Paul Phillips added a comment -

        I don't know what the proposed fix held, but here is what I meant - at the time I wrote the above, this change had no observable impact except to fix this ticket.

        https://github.com/paulp/scala/tree/issue/5130

        Show
        Paul Phillips added a comment - I don't know what the proposed fix held, but here is what I meant - at the time I wrote the above, this change had no observable impact except to fix this ticket. https://github.com/paulp/scala/tree/issue/5130
        Show
        Paul Phillips added a comment - https://github.com/scala/scala/pull/1423
        Hide
        Jason Zaugg added a comment -
        Show
        Jason Zaugg added a comment - Merged in https://github.com/scala/scala/commit/5ac896d7
        Hide
        Adriaan Moors added a comment -

        fixed for 2.11 in https://github.com/scala/scala/commit/5ac896d7 – potential backport pending

        Show
        Adriaan Moors added a comment - fixed for 2.11 in https://github.com/scala/scala/commit/5ac896d7 – potential backport pending

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Jordi Salvat i Alabart
          • Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development