Skip to content

Commit f5d1c3b

Browse files
committed
Avoid cascade type errors from error-correction-generated code
Without this commit, the testcase produces additional spurious errors: ```scala -- [E104] Syntax Error: tests/neg/i4373.scala:10:0 ----------------------------- 10 |class A2 extends _ with _ // error // error |^ |class Any is not a trait longer explanation available when compiling with `-explain` -- [E104] Syntax Error: tests/neg/i4373.scala:11:21 ---------------------------- 11 |class A3 extends Base with _ // error | ^ | class Any is not a trait longer explanation available when compiling with `-explain` -- Error: tests/neg/i4373.scala:12:24 ------------------------------------------ 12 |class A4 extends _ with Base // error | ^^^^ |illegal trait inheritance: superclass Any does not derive from trait Base's superclass Object ``` These errors make absolutely no sense for a user, since they refer to code the user didn't write, but that was generated by the compiler's error correction mechanism. I haven't checked if we could use `Ident(nme.ERROR)` everywhere. I have also tried using `EmptyTree` and `EmptyTree.withPos(wildcardPos)` and `EmptyTree.clone.withPos(wildcardPos)` as fallback trees, but all of them failed in some way.
1 parent 4e5031c commit f5d1c3b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,8 @@ object Parsers {
22872287
/** ConstrApp ::= SimpleType {ParArgumentExprs}
22882288
*/
22892289
val constrApp = () => {
2290-
val t = checkWildcard(annotType())
2290+
// Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
2291+
val t = checkWildcard(annotType(), fallbackTree = Ident(nme.ERROR))
22912292
if (in.token == LPAREN) parArgumentExprss(wrapNew(t))
22922293
else t
22932294
}

0 commit comments

Comments
 (0)