From a227ce2a197e4ca0884f517a62683960d3fcb88b Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Tue, 26 Dec 2023 16:24:32 -0800 Subject: [PATCH] Don't explain erroneous bounds --- .../dotty/tools/dotc/reporting/Message.scala | 18 ++++++++---------- tests/neg/i19334.check | 12 ++++++++++++ tests/neg/i19334.scala | 6 ++++++ 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 tests/neg/i19334.check create mode 100644 tests/neg/i19334.scala diff --git a/compiler/src/dotty/tools/dotc/reporting/Message.scala b/compiler/src/dotty/tools/dotc/reporting/Message.scala index f9abead161d2..1ac5c6ecf407 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Message.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Message.scala @@ -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 @@ -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) && !bounds.isErroneous => if (lo eq hi) i" which is an alias of $lo" else i" with $cat ${boundsStr(bounds)}" case _ => @@ -176,9 +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 => - 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 => @@ -191,7 +189,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] = { @@ -270,11 +268,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 diff --git a/tests/neg/i19334.check b/tests/neg/i19334.check new file mode 100644 index 000000000000..8c0b6b3c299e --- /dev/null +++ b/tests/neg/i19334.check @@ -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 diff --git a/tests/neg/i19334.scala b/tests/neg/i19334.scala new file mode 100644 index 000000000000..cd6af1872241 --- /dev/null +++ b/tests/neg/i19334.scala @@ -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