Skip to content

Commit

Permalink
Backport "Don't explain erroneous bounds" to LTS (#20817)
Browse files Browse the repository at this point in the history
Backports #19338 to the LTS branch.
Fixes #20134

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 28, 2024
2 parents 6941e0b + 09673f5 commit 8095737
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
18 changes: 8 additions & 10 deletions compiler/src/dotty/tools/dotc/reporting/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ object Message:
* and following recordings get consecutive superscripts starting with 2.
* @return The possibly superscripted version of `str`.
*/
def record(str: String, isType: Boolean, entry: Recorded)(using Context): String =
if !recordOK then return str
def record(str: String, isType: Boolean, entry: Recorded)(using Context): String = if !recordOK then str else
//println(s"recording $str, $isType, $entry")

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

def addendum(cat: String, info: Type): String = info match {
case bounds @ TypeBounds(lo, hi) if !(bounds =:= TypeBounds.empty) =>
case bounds @ TypeBounds(lo, hi) if !(bounds =:= TypeBounds.empty) && !bounds.isErroneous =>
if (lo eq hi) i" which is an alias of $lo"
else i" with $cat ${boundsStr(bounds)}"
case _ =>
Expand Down Expand Up @@ -155,9 +154,8 @@ object Message:
def needsExplanation(entry: Recorded) = entry match {
case param: TypeParamRef => ctx.typerState.constraint.contains(param)
case param: ParamRef => false
case skolem: SkolemType => true
case sym: Symbol =>
ctx.gadt.contains(sym) && ctx.gadt.fullBounds(sym) != TypeBounds.empty
case skolem: SkolemType => true
case sym: Symbol => ctx.gadt.contains(sym) && ctx.gadt.fullBounds(sym) != TypeBounds.empty
}

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

def columnar(parts: List[(String, String)]): List[String] = {
Expand Down Expand Up @@ -239,11 +237,11 @@ end Message
*
* Messages modify the rendendering of interpolated strings in several ways:
*
* 1. The size of the printed code is limited with a MessafeLimiter. If the message
* 1. The size of the printed code is limited with a MessageLimiter. If the message
* would get too large or too deeply nested, a `...` is printed instead.
* 2. References to module classes are prefixed with `object ` for better recogniability.
* 2. References to module classes are prefixed with `object` for better recognizability.
* 3. A where clause is sometimes added which contains the following additional explanations:
* - Rerences are disambiguated: If a message contains occurrences of the same identifier
* - References are disambiguated: If a message contains occurrences of the same identifier
* representing different symbols, the duplicates are printed with superscripts
* and the where-clause explains where each symbol is located.
* - Uninstantiated variables are explained in the where-clause with additional
Expand Down
12 changes: 12 additions & 0 deletions tests/neg/i19334.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- [E081] Type Error: tests/neg/i19334.scala:6:4 -----------------------------------------------------------------------
6 | f(_) // error was OOM formatting TypeVar(TypeParamRef(T)) when offering explanations
| ^
| Missing parameter type
|
| I could not infer the type of the parameter _$1
| in expanded function:
| _$1 => f(_$1)
| Expected type for the whole anonymous function:
| T
|
| where: T is a type variable
6 changes: 6 additions & 0 deletions tests/neg/i19334.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

def foo[T](f: T): T = ???

@main def main = foo:
def f() = ()
f(_) // error was OOM formatting TypeVar(TypeParamRef(T)) when offering explanations

0 comments on commit 8095737

Please sign in to comment.