Uploaded image for project: '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
    • Status: CLOSED
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0-M3
    • Component/s: Compiler (Misc)
    • 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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: