Skip to content

Commit e1a4cb0

Browse files
committed
Rename MemberInfo -> MemberBinding
Also change MemberInfo.exists to MemberBinding.isTypeParam.
1 parent 8c22245 commit e1a4cb0

File tree

7 files changed

+59
-36
lines changed

7 files changed

+59
-36
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,31 @@ import Names.Name
44
import Contexts.Context
55
import Types.Type
66

7-
/** The common info associated with a member symbol and a refinement */
8-
trait MemberInfo {
9-
10-
def exists(implicit ctx: Context): Boolean
11-
7+
/** A common super trait of Symbol and Refinement.
8+
* Used to capture the attributes of type parameters
9+
* which can be implemented as either symbols or refinements.
10+
*/
11+
trait MemberBinding {
12+
13+
/** Does this binding represent a type parameter?
14+
* Only in that case the rest of the binding's methods are significant.
15+
*/
16+
def isTypeParam(implicit ctx: Context): Boolean
17+
18+
/** The name of the member */
1219
def memberName(implicit ctx: Context): Name
1320

21+
/** The info of the member */
1422
def memberInfo(implicit ctx: Context): Type
1523

24+
/** The info of the member as seen from a prefix type.
25+
* This can be different from `memberInfo` if the binding
26+
* is a type symbol of a class.
27+
*/
1628
def memberInfoAsSeenFrom(pre: Type)(implicit ctx: Context): Type
1729

30+
/** The variance of the type parameter
31+
* @pre: isTypeParam = true
32+
*/
1833
def memberVariance(implicit ctx: Context): Int
19-
20-
2134
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ object Symbols {
367367
* @param coord The coordinates of the symbol (a position or an index)
368368
* @param id A unique identifier of the symbol (unique per ContextBase)
369369
*/
370-
class Symbol private[Symbols] (val coord: Coord, val id: Int) extends DotClass with MemberInfo with printing.Showable {
370+
class Symbol private[Symbols] (val coord: Coord, val id: Int) extends DotClass with MemberBinding with printing.Showable {
371371

372372
type ThisName <: Name
373373

@@ -489,8 +489,8 @@ object Symbols {
489489
*/
490490
def pos: Position = if (coord.isPosition) coord.toPosition else NoPosition
491491

492-
// MemberInfo methods
493-
def exists(implicit ctx: Context) = denot.exists
492+
// MemberBinding methods
493+
def isTypeParam(implicit ctx: Context) = denot.is(TypeParam)
494494
def memberName(implicit ctx: Context): Name = name
495495
def memberInfo(implicit ctx: Context) = denot.info
496496
def memberInfoAsSeenFrom(pre: Type)(implicit ctx: Context) = pre.memberInfo(this)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ object TypeApplications {
7575
/** Does the variance of `sym1` conform to the variance of `sym2`?
7676
* This is the case if the variances are the same or `sym` is nonvariant.
7777
*/
78-
def varianceConforms(sym1: MemberInfo, sym2: MemberInfo)(implicit ctx: Context) =
78+
def varianceConforms(sym1: MemberBinding, sym2: MemberBinding)(implicit ctx: Context) =
7979
sym1.memberVariance == sym2.memberVariance || sym2.memberVariance == 0
8080

81-
def variancesConform(syms1: List[MemberInfo], syms2: List[MemberInfo])(implicit ctx: Context) =
81+
def variancesConform(syms1: List[MemberBinding], syms2: List[MemberBinding])(implicit ctx: Context) =
8282
syms1.corresponds(syms2)(varianceConforms)
8383

8484
/** Extractor for
@@ -280,7 +280,7 @@ class TypeApplications(val self: Type) extends AnyVal {
280280
* with the bounds on its hk args. See `LambdaAbstract`, where these
281281
* types get introduced, and see `isBoundedLambda` below for the test.
282282
*/
283-
final def typeParams(implicit ctx: Context): List[MemberInfo] = /*>|>*/ track("typeParams") /*<|<*/ {
283+
final def typeParams(implicit ctx: Context): List[MemberBinding] = /*>|>*/ track("typeParams") /*<|<*/ {
284284
self match {
285285
case self: ClassInfo =>
286286
self.cls.typeParams
@@ -627,8 +627,8 @@ class TypeApplications(val self: Type) extends AnyVal {
627627
* @param args = `U1, ..., Un`
628628
* @param tparams are assumed to be the type parameters of `T`.
629629
*/
630-
final def appliedTo(args: List[Type], typParams: List[MemberInfo])(implicit ctx: Context): Type = {
631-
def matchParams(t: Type, tparams: List[MemberInfo], args: List[Type])(implicit ctx: Context): Type = args match {
630+
final def appliedTo(args: List[Type], typParams: List[MemberBinding])(implicit ctx: Context): Type = {
631+
def matchParams(t: Type, tparams: List[MemberBinding], args: List[Type])(implicit ctx: Context): Type = args match {
632632
case arg :: args1 =>
633633
try {
634634
val tparam :: tparams1 = tparams
@@ -673,7 +673,7 @@ class TypeApplications(val self: Type) extends AnyVal {
673673
/** Turn this type, which is used as an argument for
674674
* type parameter `tparam`, into a TypeBounds RHS
675675
*/
676-
final def toBounds(tparam: MemberInfo)(implicit ctx: Context): TypeBounds = self match {
676+
final def toBounds(tparam: MemberBinding)(implicit ctx: Context): TypeBounds = self match {
677677
case self: TypeBounds => // this can happen for wildcard args
678678
self
679679
case _ =>

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

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
534534
* - the type parameters of `B` match one-by-one the variances of `tparams`,
535535
* - `B` satisfies predicate `p`.
536536
*/
537-
private def testLifted(tp1: Type, tp2: Type, tparams: List[MemberInfo], p: Type => Boolean): Boolean = {
537+
private def testLifted(tp1: Type, tp2: Type, tparams: List[MemberBinding], p: Type => Boolean): Boolean = {
538538
val classBounds = tp2.member(tpnme.hkApply).info.classSymbols
539539
def recur(bcs: List[ClassSymbol]): Boolean = bcs match {
540540
case bc :: bcs1 =>
@@ -726,24 +726,31 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
726726
val rebindNeeded = tp2.refinementRefersToThis
727727
val base = if (rebindNeeded) ensureStableSingleton(tp1) else tp1
728728
val rinfo2 = if (rebindNeeded) tp2.refinedInfo.substRefinedThis(tp2, base) else tp2.refinedInfo
729+
val mbr = base.member(name)
730+
729731
def qualifies(m: SingleDenotation) = isSubType(m.info, rinfo2)
730-
def memberMatches(mbr: Denotation): Boolean = mbr match { // inlined hasAltWith for performance
732+
733+
def memberMatches: Boolean = mbr match { // inlined hasAltWith for performance
731734
case mbr: SingleDenotation => qualifies(mbr)
732735
case _ => mbr hasAltWith qualifies
733736
}
734-
/*>|>*/ ctx.traceIndented(i"hasMatchingMember($base . $name :? ${tp2.refinedInfo}) ${base.member(name).info.show} $rinfo2", subtyping) /*<|<*/ {
735-
memberMatches(base member name) ||
736-
tp1.isInstanceOf[SingletonType] &&
737-
{ // special case for situations like:
738-
// class C { type T }
739-
// val foo: C
740-
// foo.type <: C { type T = foo.T }
741-
rinfo2 match {
742-
case rinfo2: TypeAlias =>
743-
!defn.isBottomType(base.widen) && (base select name) =:= rinfo2.alias
744-
case _ => false
745-
}
746-
}
737+
738+
// special case for situations like:
739+
// class C { type T }
740+
// val foo: C
741+
// foo.type <: C { type T = foo.T }
742+
def selfReferentialMatch = tp1.isInstanceOf[SingletonType] && {
743+
rinfo2 match {
744+
case rinfo2: TypeAlias =>
745+
!defn.isBottomType(base.widen) && (base select name) =:= rinfo2.alias
746+
case _ => false
747+
}
748+
}
749+
750+
def varianceMatches = true // TODO: fill in
751+
752+
/*>|>*/ ctx.traceIndented(i"hasMatchingMember($base . $name :? ${tp2.refinedInfo}) ${mbr.info.show} $rinfo2", subtyping) /*<|<*/ {
753+
(memberMatches || selfReferentialMatch) && varianceMatches
747754
}
748755
}
749756

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ object Types {
20432043
* given the refined type itself.
20442044
*/
20452045
abstract case class RefinedType(private var myParent: Type, refinedName: Name, private var myRefinedInfo: Type)
2046-
extends RefinedOrRecType with BindingType with MemberInfo {
2046+
extends RefinedOrRecType with BindingType with MemberBinding {
20472047

20482048
final def parent = myParent
20492049
final def refinedInfo = myRefinedInfo
@@ -2082,8 +2082,11 @@ object Types {
20822082
if (parent.member(refinedName).exists) derivedRefinedType(parent, refinedName, refinedInfo)
20832083
else parent
20842084

2085-
// MemberInfo methods
2086-
def exists(implicit ctx: Context) = true
2085+
// MemberBinding methods
2086+
def isTypeParam(implicit ctx: Context) = refinedInfo match {
2087+
case tp: TypeBounds => tp.isBinding
2088+
case _ => false
2089+
}
20872090
def memberName(implicit ctx: Context) = refinedName
20882091
def memberInfo(implicit ctx: Context) = refinedInfo
20892092
def memberInfoAsSeenFrom(pre: Type)(implicit ctx: Context) = refinedInfo

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ trait TypeAssigner {
413413
case Some(tparam) => tparam
414414
case none => ntparams.find(_.name == name).getOrElse(NoSymbol)
415415
}
416-
if (tparam.exists) RefinedType(tycon, name, argtpt.tpe.toBounds(tparam))
416+
if (tparam.isTypeParam) RefinedType(tycon, name, argtpt.tpe.toBounds(tparam))
417417
else errorType(i"$tycon does not have a parameter or abstract type member named $name", arg.pos)
418418
case _ =>
419419
errorType(s"named and positional type arguments may not be mixed", arg.pos)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
934934
ctx.error(d"wrong number of type arguments for ${tpt1.tpe}, should be ${tparams.length}", tree.pos)
935935
args = args.take(tparams.length)
936936
}
937-
def typedArg(arg: untpd.Tree, tparam: MemberInfo) = {
937+
def typedArg(arg: untpd.Tree, tparam: MemberBinding) = {
938938
val (desugaredArg, argPt) =
939939
if (ctx.mode is Mode.Pattern)
940940
(if (isVarPattern(arg)) desugar.patternVar(arg) else arg, tparam.memberInfo)

0 commit comments

Comments
 (0)