-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Type infers widens union of applied abstract covariant types F[A] | F[B]
into Any
instead of F[A | B]
#12264
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
Comments
For completeness: type inference also works, if we replace the opaque type with a sealed trait: object Html {
sealed trait Tag[+N] // <<<<<
def apply[N](name: String): Tag[N] = ???
} |
This isn't specific to opaque types, it also happens with regular abstract types: object Test {
type Tag[+N]
def br: Tag[Int] = ???
def p: Tag[Long] = ???
val y = List(br, p) // infers List[Any] instead of List[Tag[AnyVal]]
} |
F[A]
+ F[B]
to F[LUB[A,B]]
F[A] | F[B]
into Any
instead of F[A | B]
The current logic for widening union is based around finding base classes, which means abstract types don't get preserved: https://github.com/lampepfl/dotty/blob/4e8ca785d5e92a0ff2fafb19deb4e6b75b74d8fc/compiler/src/dotty/tools/dotc/core/TypeOps.scala#L183-L199 @odersky do you think this logic could be adapted to allow |
Yes, I think that can work. |
Merge applied type arguments also for abstract and opaque type constructors Fixes scala#12264
Merge applied type arguments also for abstract and opaque type constructors Fixes scala#12264
Merge applied type arguments also for abstract and opaque type constructors Fixes scala#12264
Merge applied type arguments also for abstract and opaque type constructors Fixes scala#12264
Compiler version
3.0.0-RC3
Minimized code
Output
Expectation
Success.
Without opaque types
If we replace the opaque type with a case class and type alias, everything compiles successfully.
The text was updated successfully, but these errors were encountered: