Accumulate missing abstract member errors so they can all be
printed instead of only the first. Closes #2213, no review. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@21767 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
ee0f3ede52
commit
5e48dcc897
|
@ -393,12 +393,22 @@ abstract class RefChecks extends InfoTransform {
|
|||
|
||||
// 2. Check that only abstract classes have deferred members
|
||||
if (clazz.isClass && !clazz.isTrait) {
|
||||
def isClazzAbstract = clazz hasFlag ABSTRACT
|
||||
val abstractErrors = new ListBuffer[String]
|
||||
def abstractErrorMessage =
|
||||
// a little formatting polish
|
||||
if (abstractErrors.size <= 2) abstractErrors mkString " "
|
||||
else abstractErrors.tail.mkString(abstractErrors.head + ":\n", "\n", "")
|
||||
|
||||
def abstractClassError(mustBeMixin: Boolean, msg: String) {
|
||||
unit.error(clazz.pos,
|
||||
(if (clazz.isAnonymousClass || clazz.isModuleClass) "object creation impossible"
|
||||
else if (mustBeMixin) clazz.toString() + " needs to be a mixin"
|
||||
else clazz.toString() + " needs to be abstract") + ", since " + msg);
|
||||
clazz.setFlag(ABSTRACT)
|
||||
def prelude = (
|
||||
if (clazz.isAnonymousClass || clazz.isModuleClass) "object creation impossible"
|
||||
else if (mustBeMixin) clazz + " needs to be a mixin"
|
||||
else clazz + " needs to be abstract"
|
||||
) + ", since"
|
||||
|
||||
if (abstractErrors.isEmpty) abstractErrors ++= List(prelude, msg)
|
||||
else abstractErrors += msg
|
||||
}
|
||||
|
||||
def javaErasedOverridingSym(sym: Symbol): Symbol =
|
||||
|
@ -415,7 +425,7 @@ abstract class RefChecks extends InfoTransform {
|
|||
((member hasFlag JAVA) && javaErasedOverridingSym(member) != NoSymbol)
|
||||
|
||||
for (member <- clazz.tpe.nonPrivateMembersAdmitting(VBRIDGE))
|
||||
if (member.isDeferred && !(clazz hasFlag ABSTRACT) && !ignoreDeferred(member)) {
|
||||
if (member.isDeferred && !isClazzAbstract && !ignoreDeferred(member)) {
|
||||
abstractClassError(
|
||||
false, infoString(member) + " is not defined" + analyzer.varNotice(member))
|
||||
} else if ((member hasFlag ABSOVERRIDE) && member.isIncompleteIn(clazz)) {
|
||||
|
@ -449,7 +459,11 @@ abstract class RefChecks extends InfoTransform {
|
|||
if (!parents.isEmpty && parents.head.typeSymbol.hasFlag(ABSTRACT))
|
||||
checkNoAbstractDecls(parents.head.typeSymbol)
|
||||
}
|
||||
if (!(clazz hasFlag ABSTRACT)) checkNoAbstractDecls(clazz)
|
||||
if (abstractErrors.isEmpty && !isClazzAbstract)
|
||||
checkNoAbstractDecls(clazz)
|
||||
|
||||
if (abstractErrors.nonEmpty)
|
||||
unit.error(clazz.pos, abstractErrorMessage)
|
||||
}
|
||||
|
||||
/** Returns whether there is a symbol declared in class `inclazz`
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
bug2213.scala:9: error: class C needs to be abstract, since:
|
||||
value y in class A of type Int is not defined
|
||||
value x in class A of type Int is not defined
|
||||
method g in class A of type => Int is not defined
|
||||
method f in class A of type => Int is not defined
|
||||
class C extends A {}
|
||||
^
|
||||
bug2213.scala:11: error: object creation impossible, since:
|
||||
value y in class A of type Int is not defined
|
||||
value x in class A of type Int is not defined
|
||||
method g in class A of type => Int is not defined
|
||||
method f in class A of type => Int is not defined
|
||||
object Q extends A { }
|
||||
^
|
||||
two errors found
|
|
@ -0,0 +1,11 @@
|
|||
abstract class A {
|
||||
def f: Int
|
||||
def g: Int
|
||||
|
||||
val x: Int
|
||||
val y: Int
|
||||
}
|
||||
|
||||
class C extends A {}
|
||||
|
||||
object Q extends A { }
|
|
@ -1,4 +1,6 @@
|
|||
bug856.scala:3: error: class ComplexRect needs to be abstract, since method _2 in trait Product2 of type => Double is not defined
|
||||
bug856.scala:3: error: class ComplexRect needs to be abstract, since:
|
||||
method _2 in trait Product2 of type => Double is not defined
|
||||
method canEqual in trait Equals of type (that: Any)Boolean is not defined
|
||||
class ComplexRect(val _1:Double, _2:Double) extends Complex {
|
||||
^
|
||||
one error found
|
||||
|
|
Loading…
Reference in New Issue