From 387bdf9fa0bafd76b06d91d5e88f74e29143fc06 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 14 Nov 2014 18:53:40 +0100 Subject: Fine-tuning override errors for syntehtic companion objects These may raise real errors, so we cannot exclude them from overriding pairs a priori. But we can avoid reporting any errors if other override errors were reported previously for the same class. --- .../tools/dotc/transform/OverridingPairs.scala | 1 - src/dotty/tools/dotc/typer/RefChecks.scala | 25 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/dotty/tools') diff --git a/src/dotty/tools/dotc/transform/OverridingPairs.scala b/src/dotty/tools/dotc/transform/OverridingPairs.scala index 561b5fe31..f076fbc94 100644 --- a/src/dotty/tools/dotc/transform/OverridingPairs.scala +++ b/src/dotty/tools/dotc/transform/OverridingPairs.scala @@ -33,7 +33,6 @@ object OverridingPairs { protected def exclude(sym: Symbol): Boolean = sym.isConstructor || sym.is(Private) || - sym.is(Module) && sym.is(Synthetic) || // TODO: move to refchecks sym.is(ExcludedType) /** The parents of base (may also be refined). diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala index 2ae9a5b97..785998549 100644 --- a/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/src/dotty/tools/dotc/typer/RefChecks.scala @@ -107,6 +107,7 @@ object RefChecks { */ private def checkAllOverrides(clazz: Symbol)(implicit ctx: Context): Unit = { val self = clazz.thisType + var hasErrors = false case class MixinOverrideError(member: Symbol, msg: String) @@ -135,14 +136,15 @@ object RefChecks { def infoString0(sym: Symbol, showLocation: Boolean) = { val sym1 = sym.underlyingSymbol + def info = self.memberInfo(sym1) if (showLocation) sym1.showLocated else - sym1.show + - (if (sym1.isAliasType) ", which equals " + self.memberInfo(sym1) - else if (sym1.isAbstractType) " with bounds" + self.memberInfo(sym1) + i"$sym1${ + if (sym1.isAliasType) i", which equals $info" + else if (sym1.isAbstractType) i" with bounds $info" else if (sym1.is(Module)) "" - else if (sym1.isTerm) " of type " + self.memberInfo(sym1) - else "") + else if (sym1.isTerm) i" of type $info" + else ""}" } /* Check that all conditions for overriding `other` by `member` @@ -171,10 +173,15 @@ object RefChecks { "overriding %s;\n %s %s%s".format( infoStringWithLocation(other), infoString(member), msg, addendum) } - def emitOverrideError(fullmsg: String) = { - if (member.owner == clazz) ctx.error(fullmsg, member.pos) - else mixinOverrideErrors += new MixinOverrideError(member, fullmsg) - } + + def emitOverrideError(fullmsg: String) = + if (!(hasErrors && member.is(Synthetic) && member.is(Module))) { + // suppress errors relating toi synthetic companion objects if other override + // errors (e.g. relating to the companion class) have already been reported. + if (member.owner == clazz) ctx.error(fullmsg, member.pos) + else mixinOverrideErrors += new MixinOverrideError(member, fullmsg) + hasErrors = true + } def overrideError(msg: String) = { if (noErrorType) -- cgit v1.2.3