Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Don't explain erroneous bounds" to LTS #20817

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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