From 40c4fe3d8cd26a57a709c0f2bc8dcbdc5a1eaf94 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 5 Aug 2022 13:48:12 +0200 Subject: [PATCH] bugfix: Retain partial type params typying information on error Fixes https://github.com/lampepfl/dotty/issues/15750 --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 5 ++++- .../dotty/tools/languageserver/CompletionTest.scala | 10 ++++++++++ tests/neg/closure-args.scala | 2 +- tests/neg/i15750.scala | 4 ++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i15750.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 5eded211657b..ee36dd7cd55c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1993,7 +1993,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer typed(tree.tpt, AnyTypeConstructorProto) } val tparams = tpt1.tpe.typeParams - if (tparams.isEmpty) { + if tpt1.tpe.isError then + val args1 = tree.args.mapconserve(typedType(_)) + assignType(cpy.AppliedTypeTree(tree)(tpt1, args1), tpt1, args1) + else if (tparams.isEmpty) { report.error(TypeDoesNotTakeParameters(tpt1.tpe, tree.args), tree.srcPos) tpt1 } diff --git a/language-server/test/dotty/tools/languageserver/CompletionTest.scala b/language-server/test/dotty/tools/languageserver/CompletionTest.scala index b4eeb4b01d71..1657549f9a7a 100644 --- a/language-server/test/dotty/tools/languageserver/CompletionTest.scala +++ b/language-server/test/dotty/tools/languageserver/CompletionTest.scala @@ -1518,4 +1518,14 @@ class CompletionTest { .noCompletions() } + @Test def badTypeCompletions: Unit = { + code"""trait Foo + |object Test: + | def foo: ArrayBuffer[Fo${m1}] = ??? + """ + .completion(m1, Set( + ("Foo",Class,"Foo") + ) + ) + } } diff --git a/tests/neg/closure-args.scala b/tests/neg/closure-args.scala index def85f5924a1..3b166c81c61c 100644 --- a/tests/neg/closure-args.scala +++ b/tests/neg/closure-args.scala @@ -14,7 +14,7 @@ val d = xs // error .map: x => x.toString + xs.dropWhile: y => y > 0 -val c = List(xs.map: y => y + y) // error // error +val c = List(xs.map: y => y + y) // error // error // error // error val d2: String = xs // error .map: x => x.toString + xs.dropWhile: y => y > 0 // error // error .filter: z => !z.isEmpty // error diff --git a/tests/neg/i15750.scala b/tests/neg/i15750.scala new file mode 100644 index 000000000000..9cf414a0ca15 --- /dev/null +++ b/tests/neg/i15750.scala @@ -0,0 +1,4 @@ + +val foo = A[B] // error // error + +val bar = A[Int] // error