Skip to content

Fix isSubType for static objects filling in type projections #15959

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
Sep 12, 2022
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
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
thirdTryNamed(tp2)
else
( (tp1.name eq tp2.name)
&& tp1.isMemberRef
&& tp2.isMemberRef
&& tp2.isPrefixDependentMemberRef
&& isSubPrefix(tp1.prefix, tp2.prefix)
&& tp1.signature == tp2.signature
&& !(sym1.isClass && sym2.isClass) // class types don't subtype each other
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2496,8 +2496,10 @@ object Types {
symd.maybeOwner.membersNeedAsSeenFrom(prefix) && !symd.is(NonMember)
|| prefix.isInstanceOf[Types.ThisType] && symd.is(Opaque) // see pos/i11277.scala for a test where this matters

/** Is this a reference to a class or object member? */
def isMemberRef(using Context): Boolean = designator match {
/** Is this a reference to a class or object member with an info that might depend
* on the prefix?
*/
def isPrefixDependentMemberRef(using Context): Boolean = designator match {
case sym: Symbol => infoDependsOnPrefix(sym, prefix)
case _ => true
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class TreeChecker extends Phase with SymTransformer {

val sym = tree.symbol
val symIsFixed = tpe match {
case tpe: TermRef => ctx.erasedTypes || !tpe.isMemberRef
case tpe: TermRef => ctx.erasedTypes || !tpe.isPrefixDependentMemberRef
case _ => false
}
if (sym.exists && !sym.is(Private) &&
Expand Down
24 changes: 24 additions & 0 deletions tests/pos/i15931.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sealed trait TP:
type C
type P

final class Foo extends TP:
class C
enum P:
case A, B

object Bar extends TP:
class C
enum P:
case A, B, C

// Works
def test =
summon[Foo#P <:< TP#P]
val a: TP#P = Foo().P.A

// These fail
val b: TP#P = Bar.P.A: Bar.P
summon[Bar.type#P <:< TP#P]
summon[Bar.P <:< TP#P]
val c: TP#C = ??? : Bar.C
File renamed without changes.