From 300b42714e304df63272692f34480895b97ef53d Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 13 Sep 2019 22:44:05 +0200 Subject: [PATCH] Fix #7219: export forwarder should use TypeAlias for parameterless class --- .../src/dotty/tools/dotc/typer/Namer.scala | 3 ++- tests/pos-special/fatal-warnings/i7219.scala | 24 +++++++++++++++++++ tests/pos/i7219.scala | 9 +++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/pos-special/fatal-warnings/i7219.scala create mode 100644 tests/pos/i7219.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 34be6ad819bf..0a5faf69592a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -969,7 +969,8 @@ class Namer { typer: Typer => */ def fwdInfo(ref: Type, info: Type): Type = info match { case _: ClassInfo => - HKTypeLambda.fromParams(info.typeParams, ref) + if (info.typeParams.isEmpty) TypeAlias(ref) + else HKTypeLambda.fromParams(info.typeParams, ref) case _: TypeBounds => TypeAlias(ref) case info: HKTypeLambda => diff --git a/tests/pos-special/fatal-warnings/i7219.scala b/tests/pos-special/fatal-warnings/i7219.scala new file mode 100644 index 000000000000..fedfe9498b2c --- /dev/null +++ b/tests/pos-special/fatal-warnings/i7219.scala @@ -0,0 +1,24 @@ +object Foo { + enum MyEnum { + case Red + case Blue(msg: String) + } + export MyEnum._ +} + +object Bar { + type Blue = Foo.Blue + + // Related Issue -- my expectation is that + // `export Foo.Blue` should be equivalent to + // `type Blue = Foo.Blue`, but it's not: + + // export Foo.Blue // Uncommenting this (and commenting `type Blue = ...`) results in compile error +} + +import Foo._ + +def foo(a: MyEnum): Seq[Bar.Blue] = a match { + case Red => Seq.empty + case m: Foo.Blue => Seq(m) +} diff --git a/tests/pos/i7219.scala b/tests/pos/i7219.scala new file mode 100644 index 000000000000..6cb1268ba871 --- /dev/null +++ b/tests/pos/i7219.scala @@ -0,0 +1,9 @@ +class Foo { + object MyEnum { + class Blue + } + export MyEnum._ + + val a: MyEnum.Blue = ??? + a : Blue // ok +}