From f925b40ea20d464a04f40ed0ff65d4b1629bfd64 Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Tue, 7 May 2019 11:27:54 +0200 Subject: [PATCH] Fix #6322: normalize types in baseType --- .../tools/dotc/core/SymDenotations.scala | 9 +++---- .../test/dotc/pos-test-pickling.blacklist | 7 ++++-- tests/pos/6322.scala | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 tests/pos/6322.scala diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 9b4223e05f15..dc925a2afa7a 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1751,9 +1751,11 @@ object SymDenotations { Stats.record("computeBaseType, total") Stats.record(s"computeBaseType, ${tp.getClass}") } + val normed = tp.tryNormalize + if (normed.exists) return recur(normed) + tp match { case tp @ TypeRef(prefix, _) => - def foldGlb(bt: Type, ps: List[Type]): Type = ps match { case p :: ps1 => foldGlb(bt & recur(p), ps1) case _ => bt @@ -1794,7 +1796,6 @@ object SymDenotations { computeTypeRef case tp @ AppliedType(tycon, args) => - def computeApplied = { btrCache.put(tp, NoPrefix) val baseTp = @@ -1812,8 +1813,8 @@ object SymDenotations { case tp: TypeParamRef => // uncachable, since baseType depends on context bounds recur(ctx.typeComparer.bounds(tp).hi) - case tp: TypeProxy => + case tp: TypeProxy => def computeTypeProxy = { val superTp = tp.superType val baseTp = recur(superTp) @@ -1827,7 +1828,6 @@ object SymDenotations { computeTypeProxy case tp: AndOrType => - def computeAndOrType = { val tp1 = tp.tp1 val tp2 = tp.tp2 @@ -1851,6 +1851,7 @@ object SymDenotations { case JavaArrayType(_) if symbol == defn.ObjectClass => this.typeRef + case _ => NoType } diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index 5353dca296df..ac74bde3ed1b 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -1,12 +1,15 @@ i1812.scala i1867.scala i3067.scala -matchtype.scala t247.scala t2712-5.scala t284-pos.scala t3249 t3486 t3612.scala -typelevel0.scala reference + +# Match types +typelevel0.scala +matchtype.scala +6322.scala diff --git a/tests/pos/6322.scala b/tests/pos/6322.scala new file mode 100644 index 000000000000..190d7807af4e --- /dev/null +++ b/tests/pos/6322.scala @@ -0,0 +1,24 @@ +object Test { + final class A + final class B + final class C + + trait F1[T1] { + def apply(x: T1): Unit + } + + type F[N] = N match { + case A => F1[String] + case B => F[A] + case C => F[B] + } + + val s1: F[A] = ??? + s1.apply("A") + + val s2: F[B] = ??? + s2.apply("B") + + val s3: F[C] = ??? + s3.apply("C") +}