Skip to content

Commit 3065790

Browse files
committed
Added utility method: underlyingSymbol
1 parent 9d90361 commit 3065790

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,13 @@ object SymDenotations {
598598
field orElse getter
599599
}
600600

601+
/** The field accessed by a getter or setter, or
602+
* if it does not exists, the getter of a setter, or
603+
* if that does not exist the symbol itself.
604+
*/
605+
def underlyingSymbol(implicit ctx: Context): Symbol =
606+
if (is(Accessor)) accessedFieldOrGetter orElse symbol else symbol
607+
601608
/** The chain of owners of this denotation, starting with the denoting symbol itself */
602609
final def ownersIterator(implicit ctx: Context) = new Iterator[Symbol] {
603610
private[this] var current = symbol

src/dotty/tools/dotc/transform/SuperAccessors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class SuperAccessors extends MacroTransform with IdentityDenotTransformer { this
356356

357357
case Super(_, mix) =>
358358
if ((sym.isTerm) && !(sym is Method) || (sym is Accessor)) {
359-
ctx.error(s"super may be not be used on ${sym.accessedFieldOrGetter orElse sym}", tree.pos)
359+
ctx.error(s"super may be not be used on ${sym.underlyingSymbol}", tree.pos)
360360
} else if (isDisallowed(sym)) {
361361
ctx.error(s"super not allowed here: use this.${name.decode} instead", tree.pos)
362362
}

src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ast._
66
import core._
77
import Trees._
88
import Types._, ProtoTypes._, Contexts._, Decorators._, Denotations._, Symbols._
9-
import Applications._, Implicits._
9+
import Applications._, Implicits._, Flags._
1010
import util.Positions._
1111
import printing.Showable
1212
import printing.Disambiguation.disambiguated
@@ -48,6 +48,13 @@ object ErrorReporting {
4848

4949
class Errors(implicit ctx: Context) {
5050

51+
/** An explanatory note to be added to error messages
52+
* when there's a problem with abstract var defs */
53+
def abstractVarMessage(sym: Symbol): String =
54+
if (sym.underlyingSymbol.is(Mutable))
55+
"\n(Note that variables need to be initialized to be defined)"
56+
else ""
57+
5158
def expectedTypeStr(tp: Type): String = tp match {
5259
case tp: FunProto =>
5360
val result = tp.resultType match {

0 commit comments

Comments
 (0)