Skip to content

Fix #9667: Do avoidance for classbound members #10321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ object TypeOps:
def classBound(info: ClassInfo)(using Context): Type = {
val cls = info.cls
val parentType = info.parents.reduceLeft(TypeComparer.andType(_, _))
def isRefinable(sym: Symbol) =
!sym.is(Private) && !sym.isConstructor && !sym.isClass
val (refinableDecls, missingDecls) = info.decls.toList.partition(isRefinable)

def addRefinement(parent: Type, decl: Symbol) = {
val inherited =
Expand All @@ -360,26 +363,22 @@ object TypeOps:
val isPolyFunctionApply = decl.name == nme.apply && (parent <:< defn.PolyFunctionType)
val needsRefinement =
isPolyFunctionApply
|| !decl.isClass
&& {
|| {
if inheritedInfo.exists then
decl.info.widenExpr <:< inheritedInfo.widenExpr
&& !(inheritedInfo.widenExpr <:< decl.info.widenExpr)
else
parent.derivesFrom(defn.SelectableClass)
}
if needsRefinement then
RefinedType(parent, decl.name, decl.info)
.showing(i"add ref $parent $decl --> " + result, typr)
RefinedType(parent, decl.name, avoid(decl.info, missingDecls))
else parent
}

def close(tp: Type) = RecType.closeOver { rt =>
tp.subst(cls :: Nil, rt.recThis :: Nil).substThis(cls, rt.recThis)
}

def isRefinable(sym: Symbol) = !sym.is(Private) && !sym.isConstructor
val refinableDecls = info.decls.filter(isRefinable)
val raw = refinableDecls.foldLeft(parentType)(addRefinement)
HKTypeLambda.fromParams(cls.typeParams, raw) match {
case tl: HKTypeLambda => tl.derivedLambdaType(resType = close(tl.resType))
Expand Down
24 changes: 24 additions & 0 deletions tests/pos/i9667.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

def foo = new reflect.Selectable { object Foo }

trait A { type M }

val bar = new reflect.Selectable {
class C extends A
type B
type D = C
val x: C = ???
val xx: x.M = ???
val y: B = ???
val z: C = ???
val zz: z.M = ???
}
val bar1: reflect.Selectable{
type B
type D <: A
val x: A
val xx: Any
val y: this.B
val z: A
val zz: Any
} = bar