Skip to content

Commit 3f4f9fa

Browse files
committed
Adjust message pos for enum, avoid trailing space
1 parent 370f5f8 commit 3f4f9fa

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,9 @@ object RefChecks {
760760
def showDclAndLocation(sym: Symbol) =
761761
s"${sym.showDcl} in ${sym.owner.showLocated}"
762762
def undefined(msg: String) =
763-
abstractClassError(false, s"${showDclAndLocation(member)} is not defined $msg")
763+
val notdefined = s"${showDclAndLocation(member)} is not defined"
764+
val text = if !msg.isEmpty then s"$notdefined $msg" else notdefined
765+
abstractClassError(mustBeMixin = false, text)
764766
val underlying = member.underlyingSymbol
765767

766768
// Give a specific error message for abstract vars based on why it fails:
@@ -926,8 +928,19 @@ object RefChecks {
926928
if (abstractErrors.isEmpty)
927929
checkNoAbstractDecls(clazz)
928930

929-
if (abstractErrors.nonEmpty)
930-
report.error(abstractErrorMessage, clazzNamePos)
931+
def errorPos(cls: ClassSymbol) =
932+
val isEnumAnonCls = // courtesy of Checking.checkEnum
933+
cls.isAnonymousClass
934+
&& cls.owner.isTerm
935+
&& (cls.owner.flagsUNSAFE.isAllOf(EnumCase)
936+
|| ((cls.owner.name eq nme.DOLLAR_NEW) && cls.owner.flagsUNSAFE.isAllOf(Private | Synthetic)))
937+
if isEnumAnonCls then
938+
cls.parentSyms.head.children.filterNot(_.isClass).head.srcPos
939+
else
940+
clazzNamePos
941+
942+
if abstractErrors.nonEmpty then
943+
report.error(abstractErrorMessage, errorPos(clazz))
931944

932945
checkMemberTypesOK()
933946
checkCaseClassInheritanceInvariant()

tests/neg/abstract-givens.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/neg/abstract-givens.scala:11:8 -------------------------------------------------------------------------
22
11 | given s: [T] => T => Seq[T]: // error
33
| ^
4-
|instance cannot be created, since def iterator: Iterator[A] in trait IterableOnce in package scala.collection is not defined
4+
|instance cannot be created, since def iterator: Iterator[A] in trait IterableOnce in package scala.collection is not defined
55
-- [E164] Declaration Error: tests/neg/abstract-givens.scala:8:8 -------------------------------------------------------
66
8 | given y(using Int): String = summon[Int].toString * 22 // error
77
| ^

tests/neg/i19731.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/neg/i19731.scala:4:6 -----------------------------------------------------------------------------------
22
4 |class F1 extends Foo: // error
33
| ^^
4-
| class F1 needs to be abstract, since def foo(): Unit in class F1 is not defined
4+
| class F1 needs to be abstract, since def foo(): Unit in class F1 is not defined
55
-- Error: tests/neg/i19731.scala:7:6 -----------------------------------------------------------------------------------
66
7 |class F2 extends Foo: // error
77
| ^^

tests/neg/i21335.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- Error: tests/neg/i21335.scala:7:6 -----------------------------------------------------------------------------------
22
7 |class Z1 extends Bar1 // error
33
| ^^
4-
| class Z1 needs to be abstract, since override def bar(): Bar1 in trait Bar1 is not defined
4+
| class Z1 needs to be abstract, since override def bar(): Bar1 in trait Bar1 is not defined
55
-- Error: tests/neg/i21335.scala:12:6 ----------------------------------------------------------------------------------
66
12 |class Z2 extends Bar2 // error
77
| ^^
8-
| class Z2 needs to be abstract, since def bar(): Bar2 in trait Bar2 is not defined
8+
| class Z2 needs to be abstract, since def bar(): Bar2 in trait Bar2 is not defined

tests/neg/i22734.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/neg/i22734.scala:3:7 -----------------------------------------------------------------------------------
2+
3 |object X extends T // error status quo
3+
| ^
4+
| object creation impossible, since def item: String in trait T is not defined
5+
-- Error: tests/neg/i22734.scala:6:7 -----------------------------------------------------------------------------------
6+
6 | case Empty // error
7+
| ^
8+
| object creation impossible, since def item: String in class Foo is not defined

tests/neg/i22734.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait T:
2+
def item: String
3+
object X extends T // error status quo
4+
5+
enum Foo {
6+
case Empty // error
7+
case NonEmpty(item: String)
8+
case Decoy // hopefully not here
9+
10+
def item: String
11+
}

0 commit comments

Comments
 (0)