Skip to content

Commit ab63413

Browse files
committed
Sperate matchingDecl and mathingMember.
RefChecks needs both methods.
1 parent 98d2583 commit ab63413

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,20 +714,29 @@ object SymDenotations {
714714

715715
/** The non-private symbol whose name and type matches the type of this symbol
716716
* in the given class.
717-
* @param inClass The class containing the symbol's definition
717+
* @param inClass The class containing the result symbol's definition
718718
* @param site The base type from which member types are computed
719719
*
720720
* inClass <-- find denot.symbol class C { <-- symbol is here
721721
*
722722
* site: Subtype of both inClass and C
723723
*/
724-
final def matchingSymbol(inClass: Symbol, site: Type)(implicit ctx: Context): Symbol = {
724+
final def matchingDecl(inClass: Symbol, site: Type)(implicit ctx: Context): Symbol = {
725725
var denot = inClass.info.nonPrivateDecl(name)
726726
if (denot.isTerm) // types of the same name always match
727727
denot = denot.matchingDenotation(site, site.memberInfo(symbol))
728728
denot.symbol
729729
}
730730

731+
/** The non-private member of `site` whose name and type matches the type of this symbol
732+
*/
733+
final def matchingMember(site: Type)(implicit ctx: Context): Symbol = {
734+
var denot = site.nonPrivateMember(name)
735+
if (denot.isTerm) // types of the same name always match
736+
denot = denot.matchingDenotation(site, site.memberInfo(symbol))
737+
denot.symbol
738+
}
739+
731740
/** If false, this symbol cannot possibly participate in an override,
732741
* either as overrider or overridee.
733742
*/
@@ -737,7 +746,7 @@ object SymDenotations {
737746
/** The symbol, in class `inClass`, that is overridden by this denotation. */
738747
final def overriddenSymbol(inClass: ClassSymbol)(implicit ctx: Context): Symbol =
739748
if (!canMatchInheritedSymbols && (owner ne inClass)) NoSymbol
740-
else matchingSymbol(inClass, owner.thisType)
749+
else matchingDecl(inClass, owner.thisType)
741750

742751
/** All symbols overriden by this denotation. */
743752
final def allOverriddenSymbols(implicit ctx: Context): Iterator[Symbol] =
@@ -757,7 +766,7 @@ object SymDenotations {
757766
* @param ofclazz is a subclass of this symbol's owner
758767
*/
759768
final def overridingSymbol(inClass: ClassSymbol)(implicit ctx: Context): Symbol =
760-
if (canMatchInheritedSymbols) matchingSymbol(inClass, inClass.thisType)
769+
if (canMatchInheritedSymbols) matchingDecl(inClass, inClass.thisType)
761770
else NoSymbol
762771

763772
/** The symbol accessed by a super in the definition of this symbol when
@@ -767,7 +776,7 @@ object SymDenotations {
767776
final def superSymbolIn(base: Symbol)(implicit ctx: Context): Symbol = {
768777
def loop(bcs: List[ClassSymbol]): Symbol = bcs match {
769778
case bc :: bcs1 =>
770-
val sym = matchingSymbol(bcs.head, base.thisType)
779+
val sym = matchingDecl(bcs.head, base.thisType)
771780
.suchThat(alt => !(alt is Deferred)).symbol
772781
if (sym.exists) sym else loop(bcs.tail)
773782
case _ =>

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import scala.util.{Try, Success, Failure}
1717
import config.{ScalaVersion, NoScalaVersion}
1818
import typer.ErrorReporting._
1919
import DenotTransformers._
20+
import ValueClasses.isDerivedValueClass
2021

2122
object RefChecks {
2223
import tpd._
@@ -296,7 +297,7 @@ object RefChecks {
296297
printMixinOverrideErrors()
297298

298299
// Verifying a concrete class has nothing unimplemented.
299-
if (!clazz.is(Abstract)) {
300+
if (!clazz.is(AbstractOrTrait)) {
300301
val abstractErrors = new mutable.ListBuffer[String]
301302
def abstractErrorMessage =
302303
// a little formatting polish
@@ -348,8 +349,8 @@ object RefChecks {
348349

349350
val missingMethods = grouped.toList flatMap {
350351
case (name, syms) =>
351-
if (syms exists (_.symbol.isSetter)) syms filterNot (_.symbol.isGetter)
352-
else syms
352+
val withoutSetters = syms filterNot (_.symbol.isSetter)
353+
if (withoutSetters.nonEmpty) withoutSetters else syms
353354
}
354355

355356
def stubImplementations: List[String] = {
@@ -461,7 +462,7 @@ object RefChecks {
461462
def checkNoAbstractDecls(bc: Symbol): Unit = {
462463
for (decl <- bc.info.decls) {
463464
if (decl.is(Deferred) && !ignoreDeferred(decl)) {
464-
val impl = decl.matchingSymbol(bc, clazz.thisType)
465+
val impl = decl.matchingMember(clazz.thisType)
465466
if (impl == NoSymbol || (decl.owner isSubClass impl.owner)) {
466467
abstractClassError(false, "there is a deferred declaration of " + infoString(decl) +
467468
" which is not implemented in a subclass" + err.abstractVarMessage(decl))
@@ -485,7 +486,7 @@ object RefChecks {
485486
// Have to use matchingSymbol, not a method involving overridden symbols,
486487
// because the scala type system understands that an abstract method here does not
487488
// override a concrete method in Object. The jvm, however, does not.
488-
val overridden = decl.matchingSymbol(defn.ObjectClass, defn.ObjectType)
489+
val overridden = decl.matchingDecl(defn.ObjectClass, defn.ObjectType)
489490
if (overridden.is(Final))
490491
ctx.error("trait cannot redefine final method from class AnyRef", decl.pos)
491492
}
@@ -605,7 +606,7 @@ object RefChecks {
605606

606607
/** Verify classes extending AnyVal meet the requirements */
607608
private def checkAnyValSubclass(clazz: Symbol)(implicit ctx: Context) =
608-
if (clazz.isDerivedValueClass) {
609+
if (isDerivedValueClass(clazz)) {
609610
if (clazz.is(Trait))
610611
ctx.error("Only classes (not traits) are allowed to extend AnyVal", clazz.pos)
611612
else if (clazz.is(Abstract))
@@ -632,7 +633,7 @@ object RefChecks {
632633
var refSym: Symbol = _
633634

634635
override def enterReference(sym: Symbol, pos: Position): Unit =
635-
if (sym.owner.isTerm)
636+
if (sym.exists && sym.owner.isTerm)
636637
levelAndIndex.get(sym) match {
637638
case Some((level, idx)) if (level.maxIndex < idx) =>
638639
level.maxIndex = idx
@@ -676,7 +677,7 @@ class RefChecks extends MiniPhase with IdentityDenotTransformer { thisTransforme
676677
class Transform(currentLevel: RefChecks.OptLevelInfo = RefChecks.NoLevelInfo) extends TreeTransform {
677678
def phase = thisTransformer
678679
override def prepareForStats(trees: List[Tree])(implicit ctx: Context) = {
679-
println(i"preparing for $trees%; %, owner = ${ctx.owner}")
680+
// println(i"preparing for $trees%; %, owner = ${ctx.owner}")
680681
if (ctx.owner.isTerm) new Transform(new LevelInfo(currentLevel.levelAndIndex, trees))
681682
else this
682683
}
@@ -706,7 +707,7 @@ class RefChecks extends MiniPhase with IdentityDenotTransformer { thisTransforme
706707
checkOverloadedRestrictions(cls)
707708
checkAllOverrides(cls)
708709
checkAnyValSubclass(cls)
709-
if (cls.isDerivedValueClass)
710+
if (isDerivedValueClass(cls))
710711
cls.primaryConstructor.makeNotPrivateAfter(NoSymbol, thisTransformer) // SI-6601, must be done *after* pickler!
711712
tree
712713
}
@@ -721,7 +722,6 @@ class RefChecks extends MiniPhase with IdentityDenotTransformer { thisTransforme
721722
}
722723

723724
override def transformIdent(tree: Ident)(implicit ctx: Context, info: TransformerInfo) = {
724-
assert(ctx.phase.exists)
725725
checkUndesiredProperties(tree.symbol, tree.pos)
726726
currentLevel.enterReference(tree.symbol, tree.pos)
727727
tree

0 commit comments

Comments
 (0)