Skip to content

Instantly share code, notes, and snippets.

@Blaisorblade
Last active December 18, 2015 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blaisorblade/5745026 to your computer and use it in GitHub Desktop.
Save Blaisorblade/5745026 to your computer and use it in GitHub Desktop.
$ scalac -unchecked -Xprint:explicitouter,lambdalift,constructors BugOuterPart1.scala
[[syntax trees at end of explicitouter]] // BugOuterPart1.scala
package <empty> {
class Outer extends Object {
def <init>(): Outer = {
Outer.super.<init>();
()
};
final class Inner extends Object {
def <init>($outer: Outer.this.type): Outer.this.Inner = {
Inner.super.<init>();
()
};
<synthetic> <paramaccessor> private[this] val $outer: Outer.this.type = _;
<synthetic> <stable> def Outer$Inner$$$outer(): Outer = Inner.this.$outer
}
}
}
[[syntax trees at end of lambdalift]] // BugOuterPart1.scala
package <empty> {
class Outer extends Object {
def <init>(): Outer = {
Outer.super.<init>();
()
};
final class Inner extends Object {
def <init>($outer: Outer): Outer.this.Inner = {
Inner.super.<init>();
()
};
<synthetic> <paramaccessor> private[this] val $outer: Outer = _;
<synthetic> <stable> def Outer$Inner$$$outer(): Outer = Inner.this.$outer
}
}
}
[[syntax trees at end of constructors]] // BugOuterPart1.scala
package <empty> {
class Outer extends Object {
final class Inner extends Object {
def <init>($outer: Outer): Outer.this.Inner = {
Inner.super.<init>();
()
}
};
def <init>(): Outer = {
Outer.super.<init>();
()
}
}
}
class Outer {
final class Inner
}
$ scalac -unchecked -Xprint:specialize,explicitouter BugOuterPart2.scala
[[syntax trees at end of specialize]] // BugOuterPart2.scala
package <empty> {
object Matcher extends Object {
def <init>(): Matcher.type = {
Matcher.super.<init>();
()
};
def matchInner(v: Any, o: Outer): Unit = {
case <synthetic> val x1: Any = v;
case5(){
if (x1.isInstanceOf[o.Inner]().&&((x1.asInstanceOf[o.Inner](): o.Inner).<outer>().eq(o)))
matchEnd4(())
else
case6()
};
case6(){
matchEnd4(throw new MatchError(x1))
};
matchEnd4(x: Unit){
x
}
}
}
}
BugOuterPart2.scala:4: warning: The outer reference in this type test cannot be checked at run time.
case v2: o.Inner =>
^
[[syntax trees at end of explicitouter]] // BugOuterPart2.scala
package <empty> {
object Matcher extends Object {
def <init>(): Matcher.type = {
Matcher.super.<init>();
()
};
def matchInner(v: Any, o: Outer): Unit = {
case <synthetic> val x1: Any = v;
case5(){
if (x1.isInstanceOf[o.Inner]().&&(true))
matchEnd4(())
else
case6()
};
case6(){
matchEnd4(throw new MatchError(x1))
};
matchEnd4(x: Unit){
x
}
}
}
}
one warning found
object Matcher {
def matchInner(v: Any, o: Outer) =
v match {
case v2: o.Inner =>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment