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

bad explicitouter/erasure interaction regarding transform of isInstanceOf[Outer.this.Module.type] to eq(Outer.this.Module) #7598

Closed
scabug opened this issue Jun 20, 2013 · 9 comments

Comments

@scabug
Copy link

scabug commented Jun 20, 2013

package com.middlewareman

trait Component

case class Event(component: Component)

class Owner {

  object Timestamp extends Component {
    val state = System.currentTimeMillis()
    def unapply(name: Timestamp.type) = Some(name.state)
  }

  val handler: PartialFunction[Event, Unit] = {
    case Event(Timestamp(time)) => println(time)
  }

}

I have not tried compiling outside Eclipse.

@scabug
Copy link
Author

scabug commented Jun 20, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7598?orig=1
Reporter: Andreas Nyberg (middlewareman)
Affected Versions: 2.10.1, 2.10.2
Attachments:

  • SI-7598.log (created on Jun 20, 2013 3:06:59 PM UTC, 28417 bytes)

@scabug
Copy link
Author

scabug commented Jun 20, 2013

Andreas Nyberg (middlewareman) said:
Eclipse event details attached.

@scabug
Copy link
Author

scabug commented Oct 21, 2013

@retronym said:
Minimized:

class Outer {
  object X

  class Inner {
    null.isInstanceOf[X.type]
  }
}

Erasure converts instanceOf tests against singleton types to eq.

              targ.tpe match {
                case SingleType(_, _) | ThisType(_) | SuperType(_, _) =>
                  val cmpOp = if (targ.tpe <:< AnyValTpe) Any_equals else Object_eq
                  atPos(tree.pos) {
                    Apply(Select(qual, cmpOp), List(gen.mkAttributedQualifier(targ.tpe)))
                  }

After erasure:

  class Outer$Inner#8101 extends Object#145 {
    <synthetic> <paramaccessor> <artifact> protected val $outer#15239: Outer#7816 = _;
    <synthetic> <stable> <artifact> def $outer#15238(): Outer#7816 = Outer$Inner#8101.this.$outer#15239;
    def <init>#13449($outer#15240: Outer#7816): Outer$Inner#8101 = {
      if ($outer#15240.eq#5861(null))
        throw null
      else
        Outer$Inner#8101.this.$outer#15239 = $outer#15240;
      Outer$Inner#8101.super.<init>#3011();
      null.eq#5861(Outer#7816.this.X#8099());
      ()
    }

We either need explicit outer to transform TypeTrees to subsitute Outer.this with $outer.type, or change erasure to make the reference to the term Outer.this.xexplicitly pass through$outer`.

@scabug
Copy link
Author

scabug commented Oct 21, 2013

@retronym said:
scala/scala#3066

@scabug
Copy link
Author

scabug commented Feb 9, 2014

@adriaanm said:
Ping – looks like this will go to 2.11.1-RC1?

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@retronym said:
Yep. My principled fix was almost there but had some undiagnosed infinite recursions in the wild. My less principled fix (have erasure selectively call the explicitouter transformer) was a bit too much of a hack.

@scabug
Copy link
Author

scabug commented Feb 26, 2015

@adriaanm said:
This reminds me -- the spec defines isInstanceOf in terms of matching on type patterns, but that would entail y.isInstanceOf[x.type] should compile to y eq x, which actually breaks the compiler ("someone" cast a global to another global...)

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@scala scala deleted a comment from scabug Aug 26, 2022
@scala scala deleted a comment from scabug Aug 26, 2022
@SethTisue SethTisue modified the milestones: Backlog, 2.13.6 Apr 7, 2023
@SethTisue
Copy link
Member

Somehow, some way, got fixed in 2.13.6 – no compiler crash. Remains fixed in 3.2.2.

@som-snytt
Copy link

som-snytt commented Apr 7, 2023

scala/scala#9504 perchance

but the retronym minimization waited for scala/scala#9581 fixing #12312 which I must have hit while typing idly into REPL during pandemic?

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

4 participants