Skip to content

Commit 8095737

Browse files
Backport "Don't explain erroneous bounds" to LTS (#20817)
Backports #19338 to the LTS branch. Fixes #20134 PR submitted by the release tooling. [skip ci]
2 parents 6941e0b + 09673f5 commit 8095737

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ object Message:
6969
* and following recordings get consecutive superscripts starting with 2.
7070
* @return The possibly superscripted version of `str`.
7171
*/
72-
def record(str: String, isType: Boolean, entry: Recorded)(using Context): String =
73-
if !recordOK then return str
72+
def record(str: String, isType: Boolean, entry: Recorded)(using Context): String = if !recordOK then str else
7473
//println(s"recording $str, $isType, $entry")
7574

7675
/** If `e1` is an alias of another class of the same name, return the other
@@ -125,7 +124,7 @@ object Message:
125124
}
126125

127126
def addendum(cat: String, info: Type): String = info match {
128-
case bounds @ TypeBounds(lo, hi) if !(bounds =:= TypeBounds.empty) =>
127+
case bounds @ TypeBounds(lo, hi) if !(bounds =:= TypeBounds.empty) && !bounds.isErroneous =>
129128
if (lo eq hi) i" which is an alias of $lo"
130129
else i" with $cat ${boundsStr(bounds)}"
131130
case _ =>
@@ -155,9 +154,8 @@ object Message:
155154
def needsExplanation(entry: Recorded) = entry match {
156155
case param: TypeParamRef => ctx.typerState.constraint.contains(param)
157156
case param: ParamRef => false
158-
case skolem: SkolemType => true
159-
case sym: Symbol =>
160-
ctx.gadt.contains(sym) && ctx.gadt.fullBounds(sym) != TypeBounds.empty
157+
case skolem: SkolemType => true
158+
case sym: Symbol => ctx.gadt.contains(sym) && ctx.gadt.fullBounds(sym) != TypeBounds.empty
161159
}
162160

163161
val toExplain: List[(String, Recorded)] = seen.toList.flatMap { kvs =>
@@ -170,7 +168,7 @@ object Message:
170168
(tickedString, alt)
171169
}
172170
}
173-
res // help the inferrencer out
171+
res // help the inferencer out
174172
}.sortBy(_._1)
175173

176174
def columnar(parts: List[(String, String)]): List[String] = {
@@ -239,11 +237,11 @@ end Message
239237
*
240238
* Messages modify the rendendering of interpolated strings in several ways:
241239
*
242-
* 1. The size of the printed code is limited with a MessafeLimiter. If the message
240+
* 1. The size of the printed code is limited with a MessageLimiter. If the message
243241
* would get too large or too deeply nested, a `...` is printed instead.
244-
* 2. References to module classes are prefixed with `object ` for better recogniability.
242+
* 2. References to module classes are prefixed with `object` for better recognizability.
245243
* 3. A where clause is sometimes added which contains the following additional explanations:
246-
* - Rerences are disambiguated: If a message contains occurrences of the same identifier
244+
* - References are disambiguated: If a message contains occurrences of the same identifier
247245
* representing different symbols, the duplicates are printed with superscripts
248246
* and the where-clause explains where each symbol is located.
249247
* - Uninstantiated variables are explained in the where-clause with additional

tests/neg/i19334.check

Lines changed: 12 additions & 0 deletions
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

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)