Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit f8d8160

Browse files
committed
SI-8777 Avoid redundant disambiguation in error messages
When printing types in error messages, we attempt to disambiguate symbol names by qualifying them in various ways. Type paramters symbols are qualified by adding `(in someMethod)`. However, the type errors generated by higher kinded subtyping can contain clones of type parameter symbols, as creater in `isPolySubType`. The disambiguation tries fruitlessly to distinguish them but ended up adding the same suffix to both names repeatedly. ``` found : [F[_]]Foo[[X(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)]Bar[F,X(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)]] required: Foo[[X(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)]Bar[[X]Or[String,X],X(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)]] ``` This commit limits the post qualification of type parameter symbols to a single attempt to limit the damage. An alternative might be to mark a clone (we could determine its status by checking whether it is a type parameter of its owner.) But I'm not sure how to present this information in a comphrenensible way, so for now I'm limiting my ambitions to stopping the stutter.
1 parent 1531900 commit f8d8160

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ trait TypeDiagnostics {
309309
// save the name because it will be mutated until it has been
310310
// distinguished from the other types in the same error message
311311
private val savedName = sym.name
312+
private var postQualifiedWith: List[Symbol] = Nil
312313
def restoreName() = sym.name = savedName
313314
def modifyName(f: String => String) = sym setName newTypeName(f(sym.name.toString))
314315

@@ -322,7 +323,7 @@ trait TypeDiagnostics {
322323

323324
// functions to manipulate the name
324325
def preQualify() = modifyName(trueOwner.fullName + "." + _)
325-
def postQualify() = modifyName(_ + "(in " + trueOwner + ")")
326+
def postQualify() = if (!(postQualifiedWith contains trueOwner)) { postQualifiedWith ::= trueOwner; modifyName(_ + "(in " + trueOwner + ")") }
326327
def typeQualify() = if (sym.isTypeParameterOrSkolem) postQualify()
327328
def nameQualify() = if (trueOwner.isPackageClass) preQualify() else postQualify()
328329

test/files/neg/t6895b.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ t6895b.scala:20: error: could not find implicit value for parameter e: Foo[[X]Ba
22
implicitly[Foo[({type L[X] = Bar[StringOr, X]})#L]]
33
^
44
t6895b.scala:23: error: polymorphic expression cannot be instantiated to expected type;
5-
found : [F[_]]Foo[[X(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)]Bar[F,X(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)]]
6-
required: Foo[[X(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)]Bar[[X]Or[String,X],X(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)(in type L)]]
5+
found : [F[_]]Foo[[X(in type L)]Bar[F,X(in type L)]]
6+
required: Foo[[X(in type L)]Bar[[X]Or[String,X],X(in type L)]]
77
barFoo(null) : Foo[({type L[X] = Bar[StringOr, X]})#L]
88
^
99
two errors found

test/files/neg/t8777.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
t8777.scala:3: error: type mismatch;
2+
found : Foo.this.TreePrinter(in trait Printers)
3+
required: Foo.this.TreePrinter(in trait Printers)
4+
super.newCodePrinter(out, tree, printRootPkg)
5+
^
6+
one error found

test/files/neg/t8777.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait Foo extends scala.tools.nsc.Global {
2+
override def newCodePrinter(out: java.io.PrintWriter, tree: Tree, printRootPkg: Boolean): TreePrinter =
3+
super.newCodePrinter(out, tree, printRootPkg)
4+
}

0 commit comments

Comments
 (0)