From cecfb61dba312b1e3e658fb523041b367bb19634 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Tue, 19 Dec 2017 21:55:17 +0100 Subject: [PATCH 1/2] Fix #3672: avoid error on type-application of ErrorType value When a value `foo` has type `ErrorType`, `foo[Bla]` should not report an error `value foo does not take type parameters`. Instead we propagate the existing ErrorType. --- compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala | 2 ++ compiler/test-resources/repl/errmsgs | 4 ++++ tests/neg/errorTypes.scala | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 tests/neg/errorTypes.scala diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 801f654d7a57..bd7662032daf 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -411,6 +411,8 @@ trait TypeAssigner { if (sameLength(argTypes, paramNames)) pt.instantiate(argTypes) else wrongNumberOfTypeArgs(fn.tpe, pt.typeParams, args, tree.pos) } + case err: ErrorType => + err case _ => //println(i"bad type: $fn: ${fn.symbol} / ${fn.symbol.isType} / ${fn.symbol.info}") // DEBUG errorType(err.takesNoParamsStr(fn, "type "), tree.pos) diff --git a/compiler/test-resources/repl/errmsgs b/compiler/test-resources/repl/errmsgs index ca69348f8b96..711f5657babc 100644 --- a/compiler/test-resources/repl/errmsgs +++ b/compiler/test-resources/repl/errmsgs @@ -68,3 +68,7 @@ scala> while ((( foo ))) {} 1 | while ((( foo ))) {} | ^^^ | not found: foo +scala> val a: iDontExist = 1 +1 | val a: iDontExist = 1 + | ^^^^^^^^^^ + | not found: type iDontExist diff --git a/tests/neg/errorTypes.scala b/tests/neg/errorTypes.scala new file mode 100644 index 000000000000..7ebfd0332921 --- /dev/null +++ b/tests/neg/errorTypes.scala @@ -0,0 +1,5 @@ +object Test { + val x: iDontExist = 1 // error: not found: type iDontExist + + val y = x.asInstanceOf[Int] // No error reported (was: value asInstanceOf does not take type parameters) +} From f111d7ceec11bfde011901c44e4137855e98c32c Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Tue, 19 Dec 2017 21:55:29 +0100 Subject: [PATCH 2/2] Fix union with error --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 4 ++++ tests/neg/errorTypes.scala | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index fee76e379914..c940a0ec45fb 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -185,12 +185,16 @@ trait TypeOps { this: Context => // TODO: Make standalone object. tp1.rebind(approximateOr(tp1.parent, tp2)) case tp1: TypeProxy if !isClassRef(tp1) => orDominator(tp1.superType | tp2) + case err: ErrorType => + err case _ => tp2 match { case tp2: RecType => tp2.rebind(approximateOr(tp1, tp2.parent)) case tp2: TypeProxy if !isClassRef(tp2) => orDominator(tp1 | tp2.superType) + case err: ErrorType => + err case _ => val commonBaseClasses = tp.mapReduceOr(_.baseClasses)(intersect) val doms = dominators(commonBaseClasses, Nil) diff --git a/tests/neg/errorTypes.scala b/tests/neg/errorTypes.scala index 7ebfd0332921..f8d5d2795788 100644 --- a/tests/neg/errorTypes.scala +++ b/tests/neg/errorTypes.scala @@ -2,4 +2,10 @@ object Test { val x: iDontExist = 1 // error: not found: type iDontExist val y = x.asInstanceOf[Int] // No error reported (was: value asInstanceOf does not take type parameters) + + val a: iDontExist | Int = 1 // error: not found: type iDontExist + val a2 = a.isInstanceOf[Int] // No error (used to crash) + + val b: iDontExist & Int = 1 // error: not found: type iDontExist + val b2 = a.isInstanceOf[Int] // No error (worked before too) }