From 4a61719c1a3b57b47aa65409e83b87cff39145d3 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 21 Jun 2015 06:53:38 +1000 Subject: SI-8892 Fix incorrect qualification in error message Since beadafa2, we've ended up with nutty error messages for type errors involving aliases that target types in `java.lang` and `scala` packages. I think the intent of that change was to force the error messages to qualify types like `String` when needed, but to leave them unqualified by default. However, this led to this flat out wrong message in the enclosed test. found : B required: C.this.java.lang.B (which expands to) String I've changed the heuristic slightly limit this code to aliases that are eponymous with their targets. Still feels pretty kludgy, but we can at least book a little progress. --- src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala | 2 +- test/files/neg/t8892.check | 7 +++++++ test/files/neg/t8892.scala | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/files/neg/t8892.check create mode 100644 test/files/neg/t8892.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index 65dea3178b..5f2643cb25 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -318,7 +318,7 @@ trait TypeDiagnostics { */ def qualifyDefaultNamespaces() = { val intersect = Set(trueOwner, aliasOwner) intersect UnqualifiedOwners - if (intersect.nonEmpty) preQualify() + if (intersect.nonEmpty && tp.typeSymbolDirect.name == tp.typeSymbol.name) preQualify() } // functions to manipulate the name diff --git a/test/files/neg/t8892.check b/test/files/neg/t8892.check new file mode 100644 index 0000000000..5930be58c5 --- /dev/null +++ b/test/files/neg/t8892.check @@ -0,0 +1,7 @@ +t8892.scala:2: error: type mismatch; + found : B + required: C.this.B + (which expands to) String +class C[B](x: B) extends A { def f: B = x } + ^ +one error found diff --git a/test/files/neg/t8892.scala b/test/files/neg/t8892.scala new file mode 100644 index 0000000000..f857e6f115 --- /dev/null +++ b/test/files/neg/t8892.scala @@ -0,0 +1,2 @@ +trait A { type B = String } +class C[B](x: B) extends A { def f: B = x } -- cgit v1.2.3