From 7a14c056708e2e5db4382e0f7466882c66de87c8 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 27 Feb 2017 20:29:02 +0100 Subject: [PATCH 1/2] Add assert that refine infos are legal wrt refined names --- .../src/dotty/tools/dotc/core/Types.scala | 3 +++ tests/run/i2037.check | 1 + tests/run/i2037.scala | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/run/i2037.check create mode 100644 tests/run/i2037.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 200e94a1e120..f56c6a286879 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2066,6 +2066,9 @@ object Types { */ abstract case class RefinedType(parent: Type, refinedName: Name, refinedInfo: Type) extends RefinedOrRecType { + if (refinedName.isTermName) assert(refinedInfo.isInstanceOf[TermType]) + else assert(refinedInfo.isInstanceOf[TypeType]) + override def underlying(implicit ctx: Context) = parent private def badInst = diff --git a/tests/run/i2037.check b/tests/run/i2037.check new file mode 100644 index 000000000000..0abb5cd00c7b --- /dev/null +++ b/tests/run/i2037.check @@ -0,0 +1 @@ +malformed type diff --git a/tests/run/i2037.scala b/tests/run/i2037.scala new file mode 100644 index 000000000000..fdc03808a5fa --- /dev/null +++ b/tests/run/i2037.scala @@ -0,0 +1,26 @@ +import dotty.tools.dotc._ +import core._ +import Types._ +import Contexts._ +import Symbols._ +import Decorators._ + +object Test { + def f(implicit ctx: Context) = { + val badType = + RefinedType( + ctx.requiredClassRef("scala.collection.AbstractIterator"), + "GroupedIterator".toTypeName, + TypeRef(ctx.requiredClassRef("scala.collection.AbstractIterator"), "GroupedIterator".toTypeName)) + badType.member("GroupedIterator".toTypeName) + // badType.member("T".toTypeName) + } + def main(args: Array[String]): Unit = { + implicit val ctx = (new ContextBase).initialCtx + ctx.base.initialize() + try f + catch { + case ex: AssertionError => println("malformed type") + } + } +} From 7c7c1f0e55194c4902b9c3ffa1322349aaf553dc Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 3 Mar 2017 14:13:31 +0100 Subject: [PATCH 2/2] Remove test It did not work in the CI because the compiler was not found on the run classpath. In any case, the added assert helped get the callgraph to compile, so it's validated and we should get the assert in without needing the extra test. --- tests/run/i2037.check | 1 - tests/run/i2037.scala | 26 -------------------------- 2 files changed, 27 deletions(-) delete mode 100644 tests/run/i2037.check delete mode 100644 tests/run/i2037.scala diff --git a/tests/run/i2037.check b/tests/run/i2037.check deleted file mode 100644 index 0abb5cd00c7b..000000000000 --- a/tests/run/i2037.check +++ /dev/null @@ -1 +0,0 @@ -malformed type diff --git a/tests/run/i2037.scala b/tests/run/i2037.scala deleted file mode 100644 index fdc03808a5fa..000000000000 --- a/tests/run/i2037.scala +++ /dev/null @@ -1,26 +0,0 @@ -import dotty.tools.dotc._ -import core._ -import Types._ -import Contexts._ -import Symbols._ -import Decorators._ - -object Test { - def f(implicit ctx: Context) = { - val badType = - RefinedType( - ctx.requiredClassRef("scala.collection.AbstractIterator"), - "GroupedIterator".toTypeName, - TypeRef(ctx.requiredClassRef("scala.collection.AbstractIterator"), "GroupedIterator".toTypeName)) - badType.member("GroupedIterator".toTypeName) - // badType.member("T".toTypeName) - } - def main(args: Array[String]): Unit = { - implicit val ctx = (new ContextBase).initialCtx - ctx.base.initialize() - try f - catch { - case ex: AssertionError => println("malformed type") - } - } -}