Skip to content

Commit

Permalink
Don't explain erroneous bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Dec 27, 2023
1 parent 938d405 commit 4c2d5d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 8 additions & 9 deletions compiler/src/dotty/tools/dotc/reporting/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,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 @@ -146,7 +145,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) && !lo.isErroneous && !hi.isErroneous =>
if (lo eq hi) i" which is an alias of $lo"
else i" with $cat ${boundsStr(bounds)}"
case _ =>
Expand Down Expand Up @@ -176,8 +175,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 =>
case skolem: SkolemType => true
case sym: Symbol =>
ctx.gadt.contains(sym) && ctx.gadt.fullBounds(sym) != TypeBounds.empty
}

Expand All @@ -191,7 +190,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 @@ -270,11 +269,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
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 4c2d5d8

Please sign in to comment.