Skip to content

Commit 29e05aa

Browse files
authored
Fix isSubType for static objects filling in type projections (scala#15959)
Fixes scala#15931 This also fixes scala#8338, which was mis-classified as a neg test before.
2 parents ac6cd1c + 66bdfb8 commit 29e05aa

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
@@ -2504,8 +2504,10 @@ object Types {
25042504
symd.maybeOwner.membersNeedAsSeenFrom(prefix) && !symd.is(NonMember)
25052505
|| prefix.isInstanceOf[Types.ThisType] && symd.is(Opaque) // see pos/i11277.scala for a test where this matters
25062506

2507-
/** Is this a reference to a class or object member? */
2508-
def isMemberRef(using Context): Boolean = designator match {
2507+
/** Is this a reference to a class or object member with an info that might depend
2508+
* on the prefix?
2509+
*/
2510+
def isPrefixDependentMemberRef(using Context): Boolean = designator match {
25092511
case sym: Symbol => infoDependsOnPrefix(sym, prefix)
25102512
case _ => true
25112513
}

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)