Skip to content

Fix #2396: don't create refernces to packages in ElimStaticThis. #2459

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

Merged
merged 1 commit into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/ElimStaticThis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class ElimStaticThis extends MiniPhaseTransform {
override def transformIdent(tree: tpd.Ident)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
if (ctx.owner.enclosingMethod.is(JavaStatic)) {
tree.tpe match {
case TermRef(thiz: ThisType, _) if thiz.cls.is(ModuleClass) =>
case TermRef(thiz: ThisType, _) if thiz.cls.is(ModuleClass, JavaDefined) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use butNot = for clarity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure why you check JavaDefined if this is for packages, why not check Package ?

ref(thiz.cls.sourceModule).select(tree.symbol)
case TermRef(thiz: ThisType, _) =>
assert(tree.symbol.is(Flags.JavaStatic))
assert(tree.symbol.is(Flags.JavaStatic) || thiz.cls.is(JavaDefined))
tree
case _ => tree
}
Expand Down
15 changes: 15 additions & 0 deletions tests/run/i2396.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class B {
val buzz = Some(Bees.Bee("buzz")).collect {
case Bees.Bee(value) => value
}
}

object Test {
def main(args: Array[String]): Unit = {
new B
}
}

object Bees {
case class Bee(value: String)
}
15 changes: 15 additions & 0 deletions tests/run/i2396c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Bees {
import Test._

def f: PartialFunction[Bee, Unit] = {
case Test.Bee(_) => ""
// case Bee(_) => "" // This one works
}

f(new Bee("buzz"))
}

object Test {
case class Bee(value: String)
def main(args: Array[String]): Unit = new Bees
}