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

Using this.type, an expression can compile if broken into assignments and not if given inline.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0-M3
    • Component/s: Misc Compiler
    • Labels:
      None
    • Environment:

      inference

      Description

      This is the narrowest test case I could arrange. If necessary, I can provide a larger code sample where the bug actually harms clarity:

      object Bug {
        abstract class FChain {
          type T
      
          def chain(constant:String) =
            new FConstant[this.type](constant, this) //removing [this.type], everything compiles
        }
      
        case class FConstant[E <: FChain](constant:String, tail:E) extends FChain {
          type T = tail.T
        }
        
        object FNil extends FChain {
          type T = Unit
        }
      
      }
      
      import Bug._
      println("Compiles:")
      val a1 = FNil.chain("a").chain("a")
      val a2 = a1.chain("a")
      
      println("\nDoesn't compile:")
      val a = FNil.chain("a").chain("a").chain("a")
      
      

      This code is the same as the attached file.

        Activity

        Hide
        Rafael de F. Ferreira added a comment -

        Same code as provided in the description, can be run as a script or loaded in the REPL

        Show
        Rafael de F. Ferreira added a comment - Same code as provided in the description, can be run as a script or loaded in the REPL
        Hide
        Adriaan Moors added a comment -

        ok, and the error message is:

         found   : Bug.FConstant[_2.type(in value a)] where type _2.type(in value a) <: Bug.FConstant[_1.type] with Singleton
         required: Bug.FConstant[_2.type(in value a)] forSome { type _2.type(in value a) <: Bug.FConstant[_1.type] with Singleton; val _1: Bug.FConstant[Bug.FNil.type] }
          val a = FNil.chain("a").chain("a").chain("a")
              ^
        

        seems like some existential type got stripped or something.. I'll take a look ASAP.

        Show
        Adriaan Moors added a comment - ok, and the error message is: found : Bug.FConstant[_2.type(in value a)] where type _2.type(in value a) <: Bug.FConstant[_1.type] with Singleton required: Bug.FConstant[_2.type(in value a)] forSome { type _2.type(in value a) <: Bug.FConstant[_1.type] with Singleton; val _1: Bug.FConstant[Bug.FNil.type] } val a = FNil.chain("a").chain("a").chain("a") ^ seems like some existential type got stripped or something.. I'll take a look ASAP.
        Hide
        Jason Zaugg added a comment -
        Show
        Jason Zaugg added a comment - Test case in: https://github.com/scala/scala/pull/528
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/commit/e40f3c8790bfa630d0a3e554251f7ada790116da

          People

          • Assignee:
            Adriaan Moors
            Reporter:
            Rafael de F. Ferreira
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development