File tree 4 files changed +29
-3
lines changed
compiler/src/dotty/tools/dotc/core
4 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -1108,7 +1108,11 @@ object Denotations {
1108
1108
case sd : SymDenotation => true
1109
1109
case _ => info eq symbol.info
1110
1110
1111
- if ! owner.membersNeedAsSeenFrom(pre) && ((pre ne owner.thisType) || hasOriginalInfo)
1111
+ def ownerIsPrefix = pre match
1112
+ case pre : ThisType => pre.sameThis(owner.thisType)
1113
+ case _ => false
1114
+
1115
+ if ! owner.membersNeedAsSeenFrom(pre) && (! ownerIsPrefix || hasOriginalInfo)
1112
1116
|| symbol.is(NonMember )
1113
1117
then this
1114
1118
else derived(symbol.info)
Original file line number Diff line number Diff line change @@ -890,11 +890,14 @@ object SymDenotations {
890
890
* accessed via prefix `pre`?
891
891
*/
892
892
def membersNeedAsSeenFrom (pre : Type )(using Context ): Boolean =
893
+ def preIsThis = pre match
894
+ case pre : ThisType => pre.sameThis(thisType)
895
+ case _ => false
893
896
! ( this .isTerm
894
897
|| this .isStaticOwner && ! this .seesOpaques
895
898
|| ctx.erasedTypes
896
899
|| (pre eq NoPrefix )
897
- || (pre eq thisType)
900
+ || preIsThis
898
901
)
899
902
900
903
/** Is this symbol concrete, or that symbol deferred? */
Original file line number Diff line number Diff line change @@ -2636,8 +2636,11 @@ object Types {
2636
2636
* the future. See also NamedType#withDenot. Test case is neg/opaque-self-encoding.scala.
2637
2637
*/
2638
2638
private def designatorFor (prefix : Type , name : Name , denot : Denotation )(using Context ): Designator = {
2639
+ def ownerIsPrefix (owner : Symbol ) = prefix match
2640
+ case prefix : ThisType => prefix.sameThis(owner.thisType)
2641
+ case _ => false
2639
2642
val sym = denot.symbol
2640
- if (sym.exists && (prefix.eq(NoPrefix ) || prefix.ne (sym.owner.thisType )))
2643
+ if (sym.exists && (prefix.eq(NoPrefix ) || ! ownerIsPrefix (sym.owner)))
2641
2644
sym
2642
2645
else
2643
2646
name
@@ -2709,6 +2712,10 @@ object Types {
2709
2712
case that : ThisType => tref.eq(that.tref)
2710
2713
case _ => false
2711
2714
}
2715
+
2716
+ def sameThis (that : Type )(using Context ): Boolean = (that eq this ) || that.match
2717
+ case that : ThisType => this =:= that
2718
+ case _ => false
2712
2719
}
2713
2720
2714
2721
final class CachedThisType (tref : TypeRef ) extends ThisType (tref)
Original file line number Diff line number Diff line change
1
+ package opaquetypes
2
+
3
+ object `package` : // must be a package object
4
+
5
+ opaque type Foo = Double // `Foo` must be an opaque type, reference must be primitive
6
+
7
+ object Bar : // must have a wrapper object
8
+
9
+ class Baz (val i : Foo ): // must be an unqualified reference to `Foo`
10
+ def foo (that : Any ): Boolean = that match
11
+ case that1 @ (_ : Baz ) => Baz .this .i == that1.i // error: symbol for `==` changed
12
+ case _ => true
You can’t perform that action at this time.
0 commit comments