From e16271ee0a48b1a23384aa7c76b45cc750e6eada Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 31 Dec 2017 15:35:16 +0100 Subject: [PATCH 1/2] Define topLevelClass for NoDenotation Fixes #3647 --- .../tools/dotc/core/SymDenotations.scala | 13 +++++++----- tests/pos/i3647.scala | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tests/pos/i3647.scala diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 18ff1ab41dca..4d85b10a5673 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -925,11 +925,14 @@ object SymDenotations { /** The top-level class containing this denotation, * except for a toplevel module, where its module class is returned. */ - final def topLevelClass(implicit ctx: Context): Symbol = { - def topLevel(d: SymDenotation): Symbol = { - if (d.isEffectiveRoot || (d is PackageClass) || (d.owner is PackageClass)) d.symbol - else topLevel(d.owner) - } + def topLevelClass(implicit ctx: Context): Symbol = { + + def topLevel(d: SymDenotation): Symbol = + if (!exists || d.isEffectiveRoot || (d is PackageClass) || (d.owner is PackageClass)) + d.symbol + else + topLevel(d.owner) + val sym = topLevel(this) if (sym.isClass) sym else sym.moduleClass } diff --git a/tests/pos/i3647.scala b/tests/pos/i3647.scala new file mode 100644 index 000000000000..5bad3d5beb63 --- /dev/null +++ b/tests/pos/i3647.scala @@ -0,0 +1,21 @@ +object App { + def main(args: Array[String]): Unit = { + trait FooT { + type T + type Bar[A] + + def get(k: Bar[T]): String + } + val test: FooT = new FooT { + type T = String + type Bar[A] = J[A] + sealed abstract class J[A] + final case object JName extends J[T] + final case object JInt extends J[Int] + + def get(k: J[T]): String = k match { + case JName => "Age" + } + } + } +} From a84e4019b3c2fd845f74647928ace3f8d54cd729 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 2 Jan 2018 01:48:33 +0100 Subject: [PATCH 2/2] Make topLevelClass final again --- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 4d85b10a5673..17390f830ecf 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -925,7 +925,7 @@ object SymDenotations { /** The top-level class containing this denotation, * except for a toplevel module, where its module class is returned. */ - def topLevelClass(implicit ctx: Context): Symbol = { + final def topLevelClass(implicit ctx: Context): Symbol = { def topLevel(d: SymDenotation): Symbol = if (!exists || d.isEffectiveRoot || (d is PackageClass) || (d.owner is PackageClass))