Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scabug opened this issue Nov 11, 2012 · 10 comments

Comments

@scabug
Copy link

scabug commented Nov 11, 2012

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.

@scabug
Copy link
Author

scabug commented Nov 11, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6648?orig=1
Reporter: Ross A. Baker (rossabaker)
Affected Versions: 2.10.0-RC2
Other Milestones: 2.10.0
See #5578
Attachments:

  • crash.txt (created on Nov 11, 2012 4:43:34 AM UTC, 10656 bytes)
  • crash2.txt (created on Nov 11, 2012 6:27:04 AM UTC, 10606 bytes)
  • LoopTest.scala (created on Nov 11, 2012 6:27:04 AM UTC, 463 bytes)
  • LoopTest.scala (created on Nov 11, 2012 4:43:34 AM UTC, 461 bytes)

@scabug
Copy link
Author

scabug commented Nov 11, 2012

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

@scabug
Copy link
Author

scabug commented Nov 11, 2012

Ross A. Baker (rossabaker) said:
Good point on $, but still crashes the same way if $ is changed to select.

@scabug
Copy link
Author

scabug commented Nov 11, 2012

Ross A. Baker (rossabaker) said:
Changed $ to select.

@scabug
Copy link
Author

scabug commented Nov 11, 2012

@paulp said:
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)

@scabug
Copy link
Author

scabug commented Nov 11, 2012

@paulp said:
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 = {

@scabug
Copy link
Author

scabug commented Nov 11, 2012

@retronym said:
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
  }
}

@scabug
Copy link
Author

scabug commented Nov 11, 2012

@retronym said (edited on Nov 11, 2012 1:12:21 PM UTC):
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

@scabug
Copy link
Author

scabug commented Nov 11, 2012

@retronym said (edited on Nov 11, 2012 1:21:00 PM UTC):
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?

@scabug
Copy link
Author

scabug commented Nov 13, 2012

@retronym said:
scala/scala#1615

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants