Skip to content

Commit 3c04f9b

Browse files
authored
Merge pull request #10321 from dotty-staging/fix-#9667
Fix #9667: Do avoidance for classbound members
2 parents d311bf6 + 841fe01 commit 3c04f9b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ object TypeOps:
350350
def classBound(info: ClassInfo)(using Context): Type = {
351351
val cls = info.cls
352352
val parentType = info.parents.reduceLeft(TypeComparer.andType(_, _))
353+
def isRefinable(sym: Symbol) =
354+
!sym.is(Private) && !sym.isConstructor && !sym.isClass
355+
val (refinableDecls, missingDecls) = info.decls.toList.partition(isRefinable)
353356

354357
def addRefinement(parent: Type, decl: Symbol) = {
355358
val inherited =
@@ -360,26 +363,22 @@ object TypeOps:
360363
val isPolyFunctionApply = decl.name == nme.apply && (parent <:< defn.PolyFunctionType)
361364
val needsRefinement =
362365
isPolyFunctionApply
363-
|| !decl.isClass
364-
&& {
366+
|| {
365367
if inheritedInfo.exists then
366368
decl.info.widenExpr <:< inheritedInfo.widenExpr
367369
&& !(inheritedInfo.widenExpr <:< decl.info.widenExpr)
368370
else
369371
parent.derivesFrom(defn.SelectableClass)
370372
}
371373
if needsRefinement then
372-
RefinedType(parent, decl.name, decl.info)
373-
.showing(i"add ref $parent $decl --> " + result, typr)
374+
RefinedType(parent, decl.name, avoid(decl.info, missingDecls))
374375
else parent
375376
}
376377

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

381-
def isRefinable(sym: Symbol) = !sym.is(Private) && !sym.isConstructor
382-
val refinableDecls = info.decls.filter(isRefinable)
383382
val raw = refinableDecls.foldLeft(parentType)(addRefinement)
384383
HKTypeLambda.fromParams(cls.typeParams, raw) match {
385384
case tl: HKTypeLambda => tl.derivedLambdaType(resType = close(tl.resType))

tests/pos/i9667.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
def foo = new reflect.Selectable { object Foo }
3+
4+
trait A { type M }
5+
6+
val bar = new reflect.Selectable {
7+
class C extends A
8+
type B
9+
type D = C
10+
val x: C = ???
11+
val xx: x.M = ???
12+
val y: B = ???
13+
val z: C = ???
14+
val zz: z.M = ???
15+
}
16+
val bar1: reflect.Selectable{
17+
type B
18+
type D <: A
19+
val x: A
20+
val xx: Any
21+
val y: this.B
22+
val z: A
23+
val zz: Any
24+
} = bar

0 commit comments

Comments
 (0)