Skip to content

Commit 4c2d5d8

Browse files
committed
Don't explain erroneous bounds
1 parent 938d405 commit 4c2d5d8

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

compiler/src/dotty/tools/dotc/reporting/Message.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ object Message:
7676
* and following recordings get consecutive superscripts starting with 2.
7777
* @return The possibly superscripted version of `str`.
7878
*/
79-
def record(str: String, isType: Boolean, entry: Recorded)(using Context): String =
80-
if !recordOK then return str
79+
def record(str: String, isType: Boolean, entry: Recorded)(using Context): String = if !recordOK then str else
8180
//println(s"recording $str, $isType, $entry")
8281

8382
/** If `e1` is an alias of another class of the same name, return the other
@@ -146,7 +145,7 @@ object Message:
146145
}
147146

148147
def addendum(cat: String, info: Type): String = info match {
149-
case bounds @ TypeBounds(lo, hi) if !(bounds =:= TypeBounds.empty) =>
148+
case bounds @ TypeBounds(lo, hi) if !(bounds =:= TypeBounds.empty) && !lo.isErroneous && !hi.isErroneous =>
150149
if (lo eq hi) i" which is an alias of $lo"
151150
else i" with $cat ${boundsStr(bounds)}"
152151
case _ =>
@@ -176,8 +175,8 @@ object Message:
176175
def needsExplanation(entry: Recorded) = entry match {
177176
case param: TypeParamRef => ctx.typerState.constraint.contains(param)
178177
case param: ParamRef => false
179-
case skolem: SkolemType => true
180-
case sym: Symbol =>
178+
case skolem: SkolemType => true
179+
case sym: Symbol =>
181180
ctx.gadt.contains(sym) && ctx.gadt.fullBounds(sym) != TypeBounds.empty
182181
}
183182

@@ -191,7 +190,7 @@ object Message:
191190
(tickedString, alt)
192191
}
193192
}
194-
res // help the inferrencer out
193+
res // help the inferencer out
195194
}.sortBy(_._1)
196195

197196
def columnar(parts: List[(String, String)]): List[String] = {
@@ -270,11 +269,11 @@ end Message
270269
*
271270
* Messages modify the rendendering of interpolated strings in several ways:
272271
*
273-
* 1. The size of the printed code is limited with a MessafeLimiter. If the message
272+
* 1. The size of the printed code is limited with a MessageLimiter. If the message
274273
* would get too large or too deeply nested, a `...` is printed instead.
275-
* 2. References to module classes are prefixed with `object ` for better recogniability.
274+
* 2. References to module classes are prefixed with `object` for better recognizability.
276275
* 3. A where clause is sometimes added which contains the following additional explanations:
277-
* - Rerences are disambiguated: If a message contains occurrences of the same identifier
276+
* - References are disambiguated: If a message contains occurrences of the same identifier
278277
* representing different symbols, the duplicates are printed with superscripts
279278
* and the where-clause explains where each symbol is located.
280279
* - Uninstantiated variables are explained in the where-clause with additional

tests/neg/i19334.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
def foo[T](f: T): T = ???
3+
4+
@main def main = foo:
5+
def f() = ()
6+
f(_) // error was OOM formatting TypeVar(TypeParamRef(T)) when offering explanations

0 commit comments

Comments
 (0)