From 9474382efe948da34c68bce9a76890bb22e367e4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 22 Dec 2016 13:58:49 +0100 Subject: [PATCH 1/3] Fix #1845: Survive illegal this-type prefixes --- compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala | 4 +++- tests/neg/i1845.scala | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i1845.scala diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 4a97648f5825..5c07b7bcfa61 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -282,7 +282,9 @@ trait TypeAssigner { def assignType(tree: untpd.This)(implicit ctx: Context) = { val cls = qualifyingClass(tree, tree.qual.name, packageOK = false) - tree.withType(cls.thisType) + tree.withType( + if (cls.isClass) cls.thisType + else errorType("not a legal qualifying class for this", tree.pos)) } def assignType(tree: untpd.Super, qual: Tree, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context) = { diff --git a/tests/neg/i1845.scala b/tests/neg/i1845.scala new file mode 100644 index 000000000000..5cbe1900657a --- /dev/null +++ b/tests/neg/i1845.scala @@ -0,0 +1,3 @@ +object Test { + type X = FooBar22.this +} From d9e32dd34ae3efb10b6602f134e96f70988a583b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 22 Dec 2016 14:07:12 +0100 Subject: [PATCH 2/3] Add // error to neg test --- tests/neg/i1845.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/neg/i1845.scala b/tests/neg/i1845.scala index 5cbe1900657a..1ecffdc7d04d 100644 --- a/tests/neg/i1845.scala +++ b/tests/neg/i1845.scala @@ -1,3 +1,3 @@ object Test { - type X = FooBar22.this + type X = FooBar22.this // error } From 18bc638c276c56e497bd39b58c9f3acf8b09f9e0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 26 Dec 2016 15:30:26 +0700 Subject: [PATCH 3/3] Annotate other error line in test --- tests/neg/i1845.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/neg/i1845.scala b/tests/neg/i1845.scala index 1ecffdc7d04d..e3e5787e62fe 100644 --- a/tests/neg/i1845.scala +++ b/tests/neg/i1845.scala @@ -1,3 +1,3 @@ object Test { type X = FooBar22.this // error -} +} // error