Skip to content

Commit 708e640

Browse files
committed
Don't explain erroneous bounds
1 parent d2cc3ae commit 708e640

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

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

+8-10
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) && !bounds.isErroneous =>
150149
if (lo eq hi) i" which is an alias of $lo"
151150
else i" with $cat ${boundsStr(bounds)}"
152151
case _ =>
@@ -176,9 +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 =>
181-
ctx.gadt.contains(sym) && ctx.gadt.fullBounds(sym) != TypeBounds.empty
178+
case skolem: SkolemType => true
179+
case sym: Symbol => ctx.gadt.contains(sym) && ctx.gadt.fullBounds(sym) != TypeBounds.empty
182180
}
183181

184182
val toExplain: List[(String, Recorded)] = seen.toList.flatMap { kvs =>
@@ -191,7 +189,7 @@ object Message:
191189
(tickedString, alt)
192190
}
193191
}
194-
res // help the inferrencer out
192+
res // help the inferencer out
195193
}.sortBy(_._1)
196194

197195
def columnar(parts: List[(String, String)]): List[String] = {
@@ -270,11 +268,11 @@ end Message
270268
*
271269
* Messages modify the rendendering of interpolated strings in several ways:
272270
*
273-
* 1. The size of the printed code is limited with a MessafeLimiter. If the message
271+
* 1. The size of the printed code is limited with a MessageLimiter. If the message
274272
* 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.
273+
* 2. References to module classes are prefixed with `object` for better recognizability.
276274
* 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
275+
* - References are disambiguated: If a message contains occurrences of the same identifier
278276
* representing different symbols, the duplicates are printed with superscripts
279277
* and the where-clause explains where each symbol is located.
280278
* - Uninstantiated variables are explained in the where-clause with additional

tests/neg/i19334.check

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- [E081] Type Error: tests/neg/i19334.scala:6:4 -----------------------------------------------------------------------
2+
6 | f(_) // error was OOM formatting TypeVar(TypeParamRef(T)) when offering explanations
3+
| ^
4+
| Missing parameter type
5+
|
6+
| I could not infer the type of the parameter _$1
7+
| in expanded function:
8+
| _$1 => f(_$1)
9+
| Expected type for the whole anonymous function:
10+
| T
11+
|
12+
| where: T is a type variable

tests/neg/i19334.scala

+6
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)