Skip to content

Commit 66bdfb8

Browse files
committed
Fix isSubType for static objects filling in type projections
Fixes #15931
1 parent bf03086 commit 66bdfb8

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
311311
thirdTryNamed(tp2)
312312
else
313313
( (tp1.name eq tp2.name)
314-
&& tp1.isMemberRef
315-
&& tp2.isMemberRef
314+
&& tp2.isPrefixDependentMemberRef
316315
&& isSubPrefix(tp1.prefix, tp2.prefix)
317316
&& tp1.signature == tp2.signature
318317
&& !(sym1.isClass && sym2.isClass) // class types don't subtype each other

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,8 +2496,10 @@ object Types {
24962496
symd.maybeOwner.membersNeedAsSeenFrom(prefix) && !symd.is(NonMember)
24972497
|| prefix.isInstanceOf[Types.ThisType] && symd.is(Opaque) // see pos/i11277.scala for a test where this matters
24982498

2499-
/** Is this a reference to a class or object member? */
2500-
def isMemberRef(using Context): Boolean = designator match {
2499+
/** Is this a reference to a class or object member with an info that might depend
2500+
* on the prefix?
2501+
*/
2502+
def isPrefixDependentMemberRef(using Context): Boolean = designator match {
25012503
case sym: Symbol => infoDependsOnPrefix(sym, prefix)
25022504
case _ => true
25032505
}

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class TreeChecker extends Phase with SymTransformer {
385385

386386
val sym = tree.symbol
387387
val symIsFixed = tpe match {
388-
case tpe: TermRef => ctx.erasedTypes || !tpe.isMemberRef
388+
case tpe: TermRef => ctx.erasedTypes || !tpe.isPrefixDependentMemberRef
389389
case _ => false
390390
}
391391
if (sym.exists && !sym.is(Private) &&

tests/pos/i15931.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sealed trait TP:
2+
type C
3+
type P
4+
5+
final class Foo extends TP:
6+
class C
7+
enum P:
8+
case A, B
9+
10+
object Bar extends TP:
11+
class C
12+
enum P:
13+
case A, B, C
14+
15+
// Works
16+
def test =
17+
summon[Foo#P <:< TP#P]
18+
val a: TP#P = Foo().P.A
19+
20+
// These fail
21+
val b: TP#P = Bar.P.A: Bar.P
22+
summon[Bar.type#P <:< TP#P]
23+
summon[Bar.P <:< TP#P]
24+
val c: TP#C = ??? : Bar.C
File renamed without changes.

0 commit comments

Comments
 (0)