You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is inherent in opaque types that they are opaque when used from a prefix. After all, the alias is recorded in the self type of the enclosing class, and that self type is only visible if the prefix is this. So you can think of opaque types as private[this] transparent.
It is inherent in opaque types that they are opaque when used from a prefix.
This is not true when the prefix in question is the ThisType of the type defining the opaque type:
classFoo {
opaquetypeNum=Intvalz:Foo.this.Num=1
}
This works perfectly well, which is not surprising: Num and Foo.this.Num are exactly the same type, it's just that one is written with a qualifier elided and the other isn't. But the error message I got above was:
This again mentions Foo.this.Num, bu this time the compiler doesn't think that Int is a subtype of that type, but it's exactly the same type that works when you write it manually! The only difference is that the compiler created these types in different ways and ended up assigning them different denotations, this is purely an implementation detail and I don't see how this could be specified.
As far as I can tell, the issue is that
infoDependsOnPrefix
is defined as:https://github.com/lampepfl/dotty/blob/3b741d67f8631487aa553c52e03ac21157e68563/compiler/src/dotty/tools/dotc/core/Types.scala#L2300-L2301
And
membersNeedAsSeenFrom
returns true when the prefix is the currentthisType
, because we don't actually need to do an as-seen-from. But for opaque types we do need to recompute the info as a member of its thisType prefix to reveal the opaque type alias, so my best bet is that we need something like this:Which does fix the original issue, but I don't understand the full opaque type implementation well enough to say if this is good enough (for example there's a seemingly related special case in https://github.com/lampepfl/dotty/blob/3b741d67f8631487aa553c52e03ac21157e68563/compiler/src/dotty/tools/dotc/core/Denotations.scala#L1066-L1076, and I have no idea why). WDYT @odersky ?
The text was updated successfully, but these errors were encountered: