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

assertion failed in TreeGen.mkAttributedQualifier

    Details

      Description

      In Scala 2.8.1.final, the following definition causes the compiler to crash when compiling {{ (new Lift[String])((_: String).length) }}:

      class Lift[T] {                                                          
         def apply[R](f: F0[R]): T => R = f.f
      
         class F0[R](val f: T => R)
         object F0 {
            implicit def f2f0[R](fn: T => R): F0[R] = new F0(fn)
         }
      }
      

      .

      The session and stack trace:

      Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
      Type in expressions to have them evaluated.
      Type :help for more information.
      
      scala> class Lift[T] {                                                          
           |    def apply[R](f: F0[R]): T => R = f.f
           | 
           |    class F0[R](val f: T => R)
           |    object F0 {
           |       implicit def f2f0[R](fn: T => R): F0[R] = new F0(fn)
           |    }
           | }
      defined class Lift
      
      scala> (new Lift[String])((_: String).length)
      java.lang.AssertionError: assertion failed
              at scala.Predef$$.assert(Predef.scala:77)
              at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:82)
              at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:45)
              at scala.tools.nsc.ast.TreeGen.mkAttributedRef(TreeGen.scala:107)
              at scala.tools.nsc.ast.TreeGen.mkAttributedStableRef(TreeGen.scala:149)
              at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:60)
      

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          I was going to say this is fixed in trunk, because it no longer crashes the repl. But while creating a test case to guard it I found it still crashes scalac.

          class Lift[T] {                                                          
             def apply[R](f: F0[R]): T => R = f.f
          
             class F0[R](val f: T => R)
             object F0 {
                implicit def f2f0[R](fn: T => R): F0[R] = new F0(fn)
             }
          }
          
          object Test {
            def main(args: Array[String]): Unit = {
              (new Lift[String])((_: String).length)
            }
          }
          

          In the repl a type error (and the type error looks right to me):

          <console>:8: error: type mismatch;
           found   : (String) => Int
           required: _1.F0[?] where val _1: Lift[String]
                     (new Lift[String])((_: String).length)
                                                    ^
          

          Same crash outside.

          	at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:82)
          	at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:45)
          	at scala.tools.nsc.ast.TreeGen.mkAttributedRef(TreeGen.scala:107)
          	at scala.tools.nsc.ast.TreeGen.mkAttributedStableRef(TreeGen.scala:149)
          	at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:60)
          
          Show
          Paul Phillips added a comment - I was going to say this is fixed in trunk, because it no longer crashes the repl. But while creating a test case to guard it I found it still crashes scalac. class Lift[T] { def apply[R](f: F0[R]): T => R = f.f class F0[R](val f: T => R) object F0 { implicit def f2f0[R](fn: T => R): F0[R] = new F0(fn) } } object Test { def main(args: Array[String]): Unit = { (new Lift[String])((_: String).length) } } In the repl a type error (and the type error looks right to me): <console>:8: error: type mismatch; found : (String) => Int required: _1.F0[?] where val _1: Lift[String] (new Lift[String])((_: String).length) ^ Same crash outside. at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:82) at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:45) at scala.tools.nsc.ast.TreeGen.mkAttributedRef(TreeGen.scala:107) at scala.tools.nsc.ast.TreeGen.mkAttributedStableRef(TreeGen.scala:149) at scala.tools.nsc.ast.TreeGen.mkAttributedQualifier(TreeGen.scala:60)
          Hide
          Jason Zaugg added a comment -

          Minimized a little:

          class Lift {
            def apply(f: F0) {}
          
            class F0
            object F0 {
              implicit def f2f0(fn: String): F0 = ???
            }
          }
          
          object Test {
            val l = new Lift
            val f = ""
          
            "": l.FO // okay
          
            (new Lift).apply("") // fails trying to mkAttributedQualifier for pre = Skolem(_1 <: Lift with Singletom).F0
                                 // should this even have shown up in `companionImplicitMap`? It says that:
                                 //
                                 // "@return For those parts that refer to classes with companion objects that
                                 // can be accessed with unambiguous stable prefixes, the implicits infos
                                 // which are members of these companion objects."
          }
          
          Show
          Jason Zaugg added a comment - Minimized a little: class Lift { def apply(f: F0) {} class F0 object F0 { implicit def f2f0(fn: String): F0 = ??? } } object Test { val l = new Lift val f = "" "": l.FO // okay (new Lift).apply("") // fails trying to mkAttributedQualifier for pre = Skolem(_1 <: Lift with Singletom).F0 // should this even have shown up in `companionImplicitMap`? It says that: // // "@return For those parts that refer to classes with companion objects that // can be accessed with unambiguous stable prefixes, the implicits infos // which are members of these companion objects." }
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/1709

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Aaron Novstrup
              TracCC:
              Paul Phillips
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development