-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make translucentSuperType handle match types #12153
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1888,7 +1888,15 @@ object Types { | |
case st => st | ||
} | ||
|
||
/** Same as superType, except that opaque types are treated as transparent aliases */ | ||
/** Same as superType, except for two differences: | ||
* - opaque types are treated as transparent aliases | ||
* - applied type are matchtype-reduced if possible | ||
* | ||
* Note: the reason to reduce match type aliases here and not in `superType` | ||
* is that `superType` is context-independent and cached, whereas matchtype | ||
* reduction depends on context and should not be cached (at least not without | ||
* the very specific cache invalidation condition for matchtypes). | ||
*/ | ||
def translucentSuperType(using Context): Type = superType | ||
} | ||
|
||
|
@@ -4011,7 +4019,7 @@ object Types { | |
case tycon: TypeRef if tycon.symbol.isOpaqueAlias => | ||
tycon.translucentSuperType.applyIfParameterized(args) | ||
case _ => | ||
superType | ||
tryNormalize.orElse(superType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do this in translucentSuperType and not superType? At the very least it means the documentation of the base translucentSuperType in https://github.com/lampepfl/dotty/blob/f618dd66a93a962c99c22eb586dbc93d7d410988/compiler/src/dotty/tools/dotc/core/Types.scala#L1891-L1892 is now incorrect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed the comment, which now also explains why we can't do it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see we did not normalize match types when computing the signatures and erasures of inherited members. That means we did not detect logical overrides, and that means we did not generate bridges where they would have been necessary. Match types that can be reduced directly in signatures were reduced. For instance in type M[X] = X match
case Int => String
case _ => X
def test(x: M[Int]): Int = ??? the signature of |
||
} | ||
|
||
inline def map(inline op: Type => Type)(using Context) = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
case class Box[T](t: T) | ||
|
||
type Boxed[T <: Tuple] <: Tuple = T match { | ||
case EmptyTuple => EmptyTuple | ||
case h *: t => Box[h] *: Boxed[t] | ||
} | ||
|
||
trait Cmp[T <: Tuple] { def cmp(t: T, b: Boxed[T]): Boolean } | ||
|
||
object UnitCmp extends Cmp[EmptyTuple] { | ||
def cmp(t: EmptyTuple, b: EmptyTuple): Boolean = true | ||
} | ||
|
||
object UnitCmp2 extends Cmp[EmptyTuple] { | ||
def cmp(t: EmptyTuple, b: Boxed[EmptyTuple]): Boolean = true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Foo[A, B]() | ||
|
||
type FooSnd[X] = X match | ||
case Foo[_, b] => b | ||
|
||
trait Bar[A]: | ||
def bar(h: FooSnd[A]): Int | ||
|
||
val foo: Bar[Foo[String, Int]] = new Bar[Foo[String, Int]]: | ||
def bar(h: FooSnd[Foo[String, Int]]) = h |
Uh oh!
There was an error while loading. Please reload this page.