Skip to content

Commit 46a462b

Browse files
committed
Address reviewers comments
1 parent 826c96f commit 46a462b

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
2929

3030
def apply(tp: Type): Type = {
3131

32-
/** Map a `C.this` type to the right prefix. If the prefix is unstable and
33-
* the `C.this` occurs in nonvariant or contravariant position, mark the map
34-
* to be unstable.
35-
*/
32+
/** Map a `C.this` type to the right prefix. If the prefix is unstable, and
33+
* the current variance is <= 0, return a range.
34+
*/
3635
def toPrefix(pre: Type, cls: Symbol, thiscls: ClassSymbol): Type = /*>|>*/ ctx.conditionalTraceIndented(TypeOps.track, s"toPrefix($pre, $cls, $thiscls)") /*<|<*/ {
3736
if ((pre eq NoType) || (pre eq NoPrefix) || (cls is PackageClass))
3837
tp
@@ -50,16 +49,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
5049
}
5150

5251
/*>|>*/ ctx.conditionalTraceIndented(TypeOps.track, s"asSeen ${tp.show} from (${pre.show}, ${cls.show})", show = true) /*<|<*/ { // !!! DEBUG
52+
// One `case ThisType` is specific to asSeenFrom, all other cases are inlined for performance
5353
tp match {
54-
case tp: NamedType => // inlined for performance; TODO: factor out into inline method
54+
case tp: NamedType =>
5555
if (tp.symbol.isStatic) tp
56-
else {
57-
val saved = variance
58-
variance = variance max 0
59-
val prefix1 = this(tp.prefix)
60-
variance = saved
61-
derivedSelect(tp, prefix1)
62-
}
56+
else derivedSelect(tp, atVariance(variance max 0)(this(tp.prefix)))
6357
case tp: ThisType =>
6458
toPrefix(pre, cls, tp.cls)
6559
case _: BoundType | NoPrefix =>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,6 +3946,9 @@ object Types {
39463946
else if (v1 < 0 && v2 < 0) propagate(infoHi, infoLo)
39473947
else if (!infoLo.isAlias && !infoHi.isAlias) propagate(infoLo, infoHi)
39483948
else range(tp.bottomType, tp.topType)
3949+
// Using `parent` instead of `tp.topType` would be better for normal refinements,
3950+
// but it would also turn *-types to a hk-types, which is not what we want.
3951+
// We should revisit this point in case we represent applied types not as refinements anymore.
39493952
case Range(infoLo, infoHi) =>
39503953
propagate(infoLo, infoHi)
39513954
case _ =>
@@ -4015,6 +4018,7 @@ object Types {
40154018
range(tp.derivedAppliedType(tycon, loBuf.toList),
40164019
tp.derivedAppliedType(tycon, hiBuf.toList))
40174020
else range(tp.bottomType, tp.topType)
4021+
// TODO: can we give a better bound than `topType`?
40184022
}
40194023
}
40204024
else tp.derivedAppliedType(tycon, args)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ trait TypeAssigner {
4646
val parentType = info.parentsWithArgs.reduceLeft(ctx.typeComparer.andType(_, _))
4747
def addRefinement(parent: Type, decl: Symbol) = {
4848
val inherited =
49-
parentType.findMember(decl.name, info.cls.thisType, Private)
49+
parentType.findMember(decl.name, info.cls.thisType, excluded = Private)
5050
.suchThat(decl.matches(_))
5151
val inheritedInfo = inherited.info
5252
if (inheritedInfo.exists && decl.info <:< inheritedInfo && !(inheritedInfo <:< decl.info)) {
@@ -88,7 +88,7 @@ trait TypeAssigner {
8888
case info => range(tp.info.bottomType, apply(info))
8989
}
9090
case tp: TypeRef if toAvoid(tp.symbol) =>
91-
val avoided = tp.info match {
91+
tp.info match {
9292
case TypeAlias(alias) =>
9393
apply(alias)
9494
case TypeBounds(lo, hi) =>
@@ -98,7 +98,6 @@ trait TypeAssigner {
9898
case _ =>
9999
range(tp.bottomType, tp.topType) // should happen only in error cases
100100
}
101-
avoided
102101
case tp: ThisType if toAvoid(tp.cls) =>
103102
range(tp.bottomType, apply(classBound(tp.cls.classInfo)))
104103
case tp: TypeVar if ctx.typerState.constraint.contains(tp) =>

0 commit comments

Comments
 (0)