@@ -36,6 +36,8 @@ import rewrite.Rewrites.patch
36
36
import NavigateAST ._
37
37
import transform .SymUtils ._
38
38
import language .implicitConversions
39
+ import printing .SyntaxHighlighting ._
40
+ import reporting .ErrorExplanations ._
39
41
40
42
object Typer {
41
43
@@ -140,9 +142,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
140
142
* imported by <tree>
141
143
* or defined in <symbol>
142
144
*/
143
- def bindingString (prec : Int , whereFound : Context , qualifier : String = " " )(implicit ctx : Context ) =
144
- if (prec == wildImport || prec == namedImport) ex " imported $qualifier by ${whereFound.importInfo}"
145
- else ex " defined $qualifier in ${whereFound.owner}"
145
+ def bindingString (prec : Int , whereFound : Context , qualifier : String = " " ) =
146
+ if (prec == wildImport || prec == namedImport) {
147
+ ex """ imported $qualifier by ${hl " ${whereFound.importInfo.toString}" }"""
148
+ } else
149
+ ex """ defined $qualifier in ${hl " ${whereFound.owner.toString}" }"""
146
150
147
151
/** Check that any previously found result from an inner context
148
152
* does properly shadow the new one from an outer context.
@@ -165,9 +169,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
165
169
else {
166
170
if (! scala2pkg && ! previous.isError && ! found.isError) {
167
171
error(
168
- ex """ reference to $name is ambiguous;
169
- |it is both ${bindingString(newPrec, ctx, " " )}
170
- |and ${bindingString(prevPrec, prevCtx, " subsequently" )}""" ,
172
+ ex """ | reference to ` $name` is ambiguous
173
+ |it is both ${bindingString(newPrec, ctx, " " )}
174
+ |and ${bindingString(prevPrec, prevCtx, " subsequently" )}""" ,
171
175
tree.pos)
172
176
}
173
177
previous
@@ -180,7 +184,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
180
184
def checkUnambiguous (found : Type ) = {
181
185
val other = namedImportRef(site, selectors.tail)
182
186
if (other.exists && found.exists && (found != other))
183
- error(em " reference to $name is ambiguous; it is imported twice in ${ctx.tree}" ,
187
+ error(em " reference to ` $name` is ambiguous; it is imported twice in ${ctx.tree}" ,
184
188
tree.pos)
185
189
found
186
190
}
@@ -844,11 +848,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
844
848
mapOver(t)
845
849
}
846
850
}
847
- override def transform (tree : Tree )(implicit ctx : Context ) =
848
- super .transform(tree .withType(elimWildcardSym(tree .tpe))) match {
851
+ override def transform (trt : Tree )(implicit ctx : Context ) =
852
+ super .transform(trt .withType(elimWildcardSym(trt .tpe))) match {
849
853
case b : Bind =>
850
854
if (ctx.scope.lookup(b.name) == NoSymbol ) ctx.enter(b.symbol)
851
- else ctx.error( em " duplicate pattern variable: ${b.name} " , b.pos)
855
+ else ctx.explainError( DuplicateBind (b, tree) , b.pos)
852
856
b.symbol.info = elimWildcardSym(b.symbol.info)
853
857
b
854
858
case t => t
0 commit comments