From 28a7edd7f4a6322a8cef8f007dd25c7d7e8e8046 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 30 Apr 2025 09:28:26 -0700 Subject: [PATCH 1/2] Show errors in errorless test --- .../test/dotty/tools/vulpix/ParallelTesting.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 3a2f261a8e16..e6572ec81ae3 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -947,7 +947,11 @@ trait ParallelTesting extends RunnerOrchestration: Option { if actualErrors == 0 then s"\nNo errors found when compiling neg test $testSource" - else if expectedErrors == 0 then s"\nNo errors expected/defined in $testSource -- use // error or // nopos-error" + else if expectedErrors == 0 then + s"""| + |No errors expected/defined in $testSource -- use // error or // nopos-error" + |$showErrors + |""".stripMargin.trim.linesIterator.mkString("\n", "\n", "") else if expectedErrors != actualErrors then s"""|Wrong number of errors encountered when compiling $testSource |expected: $expectedErrors, actual: $actualErrors @@ -955,8 +959,10 @@ trait ParallelTesting extends RunnerOrchestration: |${unexpected.mkString("Unexpected errors:\n", "\n", "")} |$showErrors |""".stripMargin.trim.linesIterator.mkString("\n", "\n", "") - else if hasMissingAnnotations then s"\nErrors found on incorrect row numbers when compiling $testSource\n$showErrors" - else if !errorMap.isEmpty then s"\nExpected error(s) have {=}: $errorMap" + else if hasMissingAnnotations then + s"\nErrors found on incorrect row numbers when compiling $testSource\n$showErrors" + else if !errorMap.isEmpty then + s"\nExpected error(s) have {=}: $errorMap" else null } end maybeFailureMessage From da48b63b6437e643a57741d738b92edb304747b4 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 30 Apr 2025 09:28:46 -0700 Subject: [PATCH 2/2] Adjust message pos for enum, avoid trailing space --- .../dotty/tools/dotc/typer/RefChecks.scala | 19 ++++++++++++--- tests/neg/abstract-givens.check | 2 +- tests/neg/i19731.check | 2 +- tests/neg/i21335.check | 4 ++-- tests/neg/i22734.check | 8 +++++++ tests/neg/i22734.scala | 23 +++++++++++++++++++ tests/neg/i22941.check | 2 +- 7 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 tests/neg/i22734.check create mode 100644 tests/neg/i22734.scala diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 7037a9a986aa..328ba7a2b5a3 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -760,7 +760,9 @@ object RefChecks { def showDclAndLocation(sym: Symbol) = s"${sym.showDcl} in ${sym.owner.showLocated}" def undefined(msg: String) = - abstractClassError(false, s"${showDclAndLocation(member)} is not defined $msg") + val notdefined = s"${showDclAndLocation(member)} is not defined" + val text = if !msg.isEmpty then s"$notdefined $msg" else notdefined + abstractClassError(mustBeMixin = false, text) val underlying = member.underlyingSymbol // Give a specific error message for abstract vars based on why it fails: @@ -926,8 +928,19 @@ object RefChecks { if (abstractErrors.isEmpty) checkNoAbstractDecls(clazz) - if (abstractErrors.nonEmpty) - report.error(abstractErrorMessage, clazzNamePos) + def errorPos(cls: ClassSymbol) = + val isEnumAnonCls = // courtesy of Checking.checkEnum + cls.isAnonymousClass + && cls.owner.isTerm + && (cls.owner.flagsUNSAFE.isAllOf(EnumCase) + || ((cls.owner.name eq nme.DOLLAR_NEW) && cls.owner.flagsUNSAFE.isAllOf(Private | Synthetic))) + if isEnumAnonCls then + cls.parentSyms.head.children.filterNot(_.isClass).head.srcPos + else + clazzNamePos + + if abstractErrors.nonEmpty then + report.error(abstractErrorMessage, errorPos(clazz)) checkMemberTypesOK() checkCaseClassInheritanceInvariant() diff --git a/tests/neg/abstract-givens.check b/tests/neg/abstract-givens.check index 51f50db266c2..534ebdd4e8c0 100644 --- a/tests/neg/abstract-givens.check +++ b/tests/neg/abstract-givens.check @@ -1,7 +1,7 @@ -- Error: tests/neg/abstract-givens.scala:11:8 ------------------------------------------------------------------------- 11 | given s: [T] => T => Seq[T]: // error | ^ - |instance cannot be created, since def iterator: Iterator[A] in trait IterableOnce in package scala.collection is not defined + |instance cannot be created, since def iterator: Iterator[A] in trait IterableOnce in package scala.collection is not defined -- [E164] Declaration Error: tests/neg/abstract-givens.scala:8:8 ------------------------------------------------------- 8 | given y(using Int): String = summon[Int].toString * 22 // error | ^ diff --git a/tests/neg/i19731.check b/tests/neg/i19731.check index 5c6ef5246b1d..e5c31618c29c 100644 --- a/tests/neg/i19731.check +++ b/tests/neg/i19731.check @@ -1,7 +1,7 @@ -- Error: tests/neg/i19731.scala:4:6 ----------------------------------------------------------------------------------- 4 |class F1 extends Foo: // error | ^^ - | class F1 needs to be abstract, since def foo(): Unit in class F1 is not defined + | class F1 needs to be abstract, since def foo(): Unit in class F1 is not defined -- Error: tests/neg/i19731.scala:7:6 ----------------------------------------------------------------------------------- 7 |class F2 extends Foo: // error | ^^ diff --git a/tests/neg/i21335.check b/tests/neg/i21335.check index ae2e09df1f61..fbd8d97e8a67 100644 --- a/tests/neg/i21335.check +++ b/tests/neg/i21335.check @@ -1,8 +1,8 @@ -- Error: tests/neg/i21335.scala:7:6 ----------------------------------------------------------------------------------- 7 |class Z1 extends Bar1 // error | ^^ - | class Z1 needs to be abstract, since override def bar(): Bar1 in trait Bar1 is not defined + | class Z1 needs to be abstract, since override def bar(): Bar1 in trait Bar1 is not defined -- Error: tests/neg/i21335.scala:12:6 ---------------------------------------------------------------------------------- 12 |class Z2 extends Bar2 // error | ^^ - | class Z2 needs to be abstract, since def bar(): Bar2 in trait Bar2 is not defined + | class Z2 needs to be abstract, since def bar(): Bar2 in trait Bar2 is not defined diff --git a/tests/neg/i22734.check b/tests/neg/i22734.check new file mode 100644 index 000000000000..c3c02c671b8d --- /dev/null +++ b/tests/neg/i22734.check @@ -0,0 +1,8 @@ +-- Error: tests/neg/i22734.scala:4:7 ----------------------------------------------------------------------------------- +4 |object X extends T // error via refchecks + | ^ + | object creation impossible, since def item: String in trait T is not defined +-- Error: tests/neg/i22734.scala:7:7 ----------------------------------------------------------------------------------- +7 | case Empty // error via refchecks + | ^ + | object creation impossible, since def item: String in class Foo is not defined diff --git a/tests/neg/i22734.scala b/tests/neg/i22734.scala new file mode 100644 index 000000000000..f70387d16258 --- /dev/null +++ b/tests/neg/i22734.scala @@ -0,0 +1,23 @@ +trait T: + def item: String + +object X extends T // error via refchecks + +enum Foo { + case Empty // error via refchecks + case NonEmpty(item: String) + case Decoy // missing error + + def item: String +} + +trait TCell extends T: + override def item: String = "tcell" + +enum Bar: + case Baz extends Bar, TCell // simple case inherits definition + def item: String + +@main def test = + println: + Bar.Baz.item diff --git a/tests/neg/i22941.check b/tests/neg/i22941.check index 81edebd098d3..97159605d9e0 100644 --- a/tests/neg/i22941.check +++ b/tests/neg/i22941.check @@ -1,4 +1,4 @@ -- Error: tests/neg/i22941.scala:4:6 ----------------------------------------------------------------------------------- 4 |class Baz extends Foo: // error | ^^^ - | class Baz needs to be abstract, since def bar: String in trait Foo is not defined + | class Baz needs to be abstract, since def bar: String in trait Foo is not defined