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

Compiler crash: can't convert from REF(anonymous class anon$1) to REF(anonymous class anon)

    Details

      Description

      The attached file compiles under Scala 2.9.2, crashes under 2.10.0-RC2 and the latest snapshot (2.10.0-20121104-170503-8b598436f6). Test case is a simplifed version of Scalate's LoopTest.

      1. crash.txt
        10 kB
        Ross A. Baker
      2. crash2.txt
        10 kB
        Ross A. Baker
      3. LoopTest.scala
        0.5 kB
        Ross A. Baker
      4. LoopTest.scala
        0.5 kB
        Ross A. Baker

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          "The ‘$’ character is reserved for compiler-synthesized identifiers. User programs should not define identifiers which contain ‘$’ characters."

          Show
          Paul Phillips added a comment - "The ‘$’ character is reserved for compiler-synthesized identifiers. User programs should not define identifiers which contain ‘$’ characters."
          Hide
          Ross A. Baker added a comment -

          Good point on $, but still crashes the same way if $ is changed to select.

          Show
          Ross A. Baker added a comment - Good point on $ , but still crashes the same way if $ is changed to select .
          Hide
          Ross A. Baker added a comment -

          Changed $ to select.

          Show
          Ross A. Baker added a comment - Changed $ to select .
          Hide
          Paul Phillips added a comment -

          Regressed in:

          commit ae5ff6628bb74c16d871a2ada0664cdd5d2399a5
          Author: Paul Phillips <paulp@improving.org>
          Date:   Tue May 1 19:08:41 2012 -0700
          
              Fixes #SI-5578.
              ResetAttrs shouldn't be side-effecting on the original tree,
              since it can lead to NPEs in erroneous trees (or maybe even for valid ones?).
              Review by @odersky
              
              (Patch by plocinic, applied without his complicity by extempore)
          
          Show
          Paul Phillips added a comment - Regressed in: commit ae5ff6628bb74c16d871a2ada0664cdd5d2399a5 Author: Paul Phillips <paulp@improving.org> Date: Tue May 1 19:08:41 2012 -0700 Fixes #SI-5578. ResetAttrs shouldn't be side-effecting on the original tree, since it can lead to NPEs in erroneous trees (or maybe even for valid ones?). Review by @odersky (Patch by plocinic, applied without his complicity by extempore)
          Hide
          Paul Phillips added a comment -

          Seems to go wrong in flatten.

          <     def <init>($outer: anonymous class LoopTest$transformer1$$anonfun$1$$anonfun$apply$1): anonymous class $anonfun$$anon = {
          ---
          >     def <init>($outer: anonymous class LoopTest$transformer1$$anonfun$1$$anonfun$apply$1): anonymous class LoopTest$transformer1$$anonfun$1$$anonfun$apply$1$$anon$1 = {
          
          Show
          Paul Phillips added a comment - Seems to go wrong in flatten. < def <init>($outer: anonymous class LoopTest$transformer1$$anonfun$1$$anonfun$apply$1): anonymous class $anonfun$$anon = { --- > def <init>($outer: anonymous class LoopTest$transformer1$$anonfun$1$$anonfun$apply$1): anonymous class LoopTest$transformer1$$anonfun$1$$anonfun$apply$1$$anon$1 = {
          Hide
          Jason Zaugg added a comment -

          Here's a better look at it:

          abstract class Node extends NodeSeq
          trait NodeSeq extends Seq[Node]
          object NodeSeq {
            implicit def seqToNodeSeq(ns: Seq[Node]): NodeSeq = ???
          }
          
          class Transformer {
            def apply(nodes: Any): Any = ???
          }
          
          class LoopTest {
            def foo[B, That](f: Seq[B])(implicit bf: scala.collection.generic.CanBuildFrom[Seq[Int], B, That]): That = ???
          
            object transformer1 extends Transformer {
              // Adding explicit type arguments, or making the impilcit view
              // seqToNodeSeq explicit avoids the crash
              foo {
                // These both avoid the crash:
                // {val t = new Transformer {}; t.apply(null)
                // new Transformer().apply(null)
                new Transformer {}.apply(null)
          
                null: NodeSeq
              }: NodeSeq
            }
          }
          
          Show
          Jason Zaugg added a comment - Here's a better look at it: abstract class Node extends NodeSeq trait NodeSeq extends Seq[Node] object NodeSeq { implicit def seqToNodeSeq(ns: Seq[Node]): NodeSeq = ??? } class Transformer { def apply(nodes: Any): Any = ??? } class LoopTest { def foo[B, That](f: Seq[B])(implicit bf: scala.collection.generic.CanBuildFrom[Seq[Int], B, That]): That = ??? object transformer1 extends Transformer { // Adding explicit type arguments, or making the impilcit view // seqToNodeSeq explicit avoids the crash foo { // These both avoid the crash: // {val t = new Transformer {}; t.apply(null) // new Transformer().apply(null) new Transformer {}.apply(null) null: NodeSeq }: NodeSeq } }
          Hide
          Jason Zaugg added a comment - - edited

          Paul: I've been poking around at this one, it seems similar to the problems we're trying sort out in macro-land.

          This will fix it:

          https://github.com/retronym/scala/compare/ticket/6648

          But I expect we can do a bit better, seems like it should be handled in the existing wasEmpty checks. Any insights to share? I'm all ears.

          By resetting that return type, we only end up with one $anon symbol after typer.

          Before:

          *             object transformer1#12052
          *                 constructor transformer1#15334
          *                 value <local transformer1>#15335
          *                     anonymous class $anon#15341 (final)
          *                     anonymous class $anon#21138 (final)
          *                         constructor $anon#21139
          *                         value <local $anon>#21141
          *             object transformer1#12051 (private)
          

          After:

            object transformer1#6962
          * object transformer1#6963
          *     constructor transformer1#15504
          *     value <local transformer1>#15505
          *         anonymous class $anon#21364 (final)
          *             constructor $anon#21365
          *             value <local $anon>#21367
          
          Show
          Jason Zaugg added a comment - - edited Paul: I've been poking around at this one, it seems similar to the problems we're trying sort out in macro-land. This will fix it: https://github.com/retronym/scala/compare/ticket/6648 But I expect we can do a bit better, seems like it should be handled in the existing wasEmpty checks. Any insights to share? I'm all ears. By resetting that return type, we only end up with one $anon symbol after typer. Before: * object transformer1#12052 * constructor transformer1#15334 * value <local transformer1>#15335 * anonymous class $anon#15341 (final) * anonymous class $anon#21138 (final) * constructor $anon#21139 * value <local $anon>#21141 * object transformer1#12051 (private) After: object transformer1#6962 * object transformer1#6963 * constructor transformer1#15504 * value <local transformer1>#15505 * anonymous class $anon#21364 (final) * constructor $anon#21365 * value <local $anon>#21367
          Hide
          Jason Zaugg added a comment - - edited

          BTW, do we have a place to do symbol validations, to check for symbols with the same name/owner sneaking through? Is that always a bug?

          Show
          Jason Zaugg added a comment - - edited BTW, do we have a place to do symbol validations, to check for symbols with the same name/owner sneaking through? Is that always a bug?
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/1615

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Ross A. Baker
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development