File tree 4 files changed +31
-3
lines changed
compiler/src/dotty/tools/dotc/core
4 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -1110,7 +1110,11 @@ object Denotations {
1110
1110
case sd : SymDenotation => true
1111
1111
case _ => info eq symbol.info
1112
1112
1113
- if ! owner.membersNeedAsSeenFrom(pre) && ((pre ne owner.thisType) || hasOriginalInfo)
1113
+ def ownerIsPrefix = pre match
1114
+ case pre : ThisType => pre.sameThis(owner.thisType)
1115
+ case _ => false
1116
+
1117
+ if ! owner.membersNeedAsSeenFrom(pre) && (! ownerIsPrefix || hasOriginalInfo)
1114
1118
|| symbol.is(NonMember )
1115
1119
then this
1116
1120
else derived(symbol.info)
Original file line number Diff line number Diff line change @@ -896,11 +896,14 @@ object SymDenotations {
896
896
* accessed via prefix `pre`?
897
897
*/
898
898
def membersNeedAsSeenFrom (pre : Type )(using Context ): Boolean =
899
+ def preIsThis = pre match
900
+ case pre : ThisType => pre.sameThis(thisType)
901
+ case _ => false
899
902
! ( this .isTerm
900
903
|| this .isStaticOwner && ! this .seesOpaques
901
904
|| ctx.erasedTypes
902
905
|| (pre eq NoPrefix )
903
- || (pre eq thisType)
906
+ || preIsThis
904
907
)
905
908
906
909
/** Is this symbol concrete, or that symbol deferred? */
Original file line number Diff line number Diff line change @@ -2663,8 +2663,11 @@ object Types {
2663
2663
* the future. See also NamedType#withDenot. Test case is neg/opaque-self-encoding.scala.
2664
2664
*/
2665
2665
private def designatorFor (prefix : Type , name : Name , denot : Denotation )(using Context ): Designator = {
2666
+ def ownerIsPrefix (owner : Symbol ) = prefix match
2667
+ case prefix : ThisType => prefix.sameThis(owner.thisType)
2668
+ case _ => false
2666
2669
val sym = denot.symbol
2667
- if (sym.exists && (prefix.eq(NoPrefix ) || prefix.ne (sym.owner.thisType )))
2670
+ if (sym.exists && (prefix.eq(NoPrefix ) || ! ownerIsPrefix (sym.owner)))
2668
2671
sym
2669
2672
else
2670
2673
name
@@ -2736,6 +2739,12 @@ object Types {
2736
2739
case that : ThisType => tref.eq(that.tref)
2737
2740
case _ => false
2738
2741
}
2742
+
2743
+ /** Check that the rhs is a ThisType that refers to the same class.
2744
+ */
2745
+ def sameThis (that : Type )(using Context ): Boolean = (that eq this ) || that.match
2746
+ case that : ThisType => this .cls eq that.cls
2747
+ case _ => false
2739
2748
}
2740
2749
2741
2750
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