From b1ce4f4127a35af9facb592999eec9e49b70f1cf Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 18 Mar 2019 09:49:40 +0100 Subject: [PATCH] Fix #6061: Handle malformed opaque type aliases --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 4 +++- tests/neg/i6061.scala | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i6061.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index f1ba950f1cd2..0d5a5aa2e341 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1039,7 +1039,7 @@ class Namer { typer: Typer => val finalSelfInfo: TypeOrSymbol = if (cls.isOpaqueCompanion) { // The self type of an opaque companion is refined with the type-alias of the original opaque type - def refineOpaqueCompanionSelfType(mt: Type, stats: List[Tree]): RefinedType = (stats: @unchecked) match { + def refineOpaqueCompanionSelfType(mt: Type, stats: List[Tree]): Type = (stats: @unchecked) match { case (td @ TypeDef(localName, rhs)) :: _ if td.mods.is(SyntheticOpaque) && localName == name.stripModuleClassSuffix => // create a context owned by the current opaque helper symbol, @@ -1053,6 +1053,8 @@ class Namer { typer: Typer => RefinedType(mt, localName, bounds) case _ :: stats1 => refineOpaqueCompanionSelfType(mt, stats1) + case _ => + mt // can happen for malformed inputs. } selfInfo match { case self: Type => diff --git a/tests/neg/i6061.scala b/tests/neg/i6061.scala new file mode 100644 index 000000000000..b1028d2889b3 --- /dev/null +++ b/tests/neg/i6061.scala @@ -0,0 +1,2 @@ +opaque object + // error \ No newline at end of file