Skip to content

Commit 19915b8

Browse files
sjrdodersky
authored andcommitted
Match types: fix wildcard captures handling to match intent.
As demonstrated by scala/scala3#19607, picking `H` does *not* in fact always work. It was always the intent of the spec to pick an instantiation that would make subtyping work, but the particular choice was wrong. IMO this is therefore clearly a spec bug, and we can address it irrespective of compatibility concerns.
1 parent 28a7396 commit 19915b8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

content/match-types-spec.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ At the top level, `variance = 1` and `scrutIsWidenedAbstract = false`.
253253
* If `P` is a `TypeWithoutCapture`:
254254
* Do nothing (always succeed).
255255
* If `P` is a `WildcardCapture` `ti = _`:
256-
* If `X` is of the form `_ >: L <: H`, instantiate `ti := H` (anything between `L` and `H` would work here),
257-
* Otherwise, instantiate `ti := X`.
256+
* Instantiate `ti` so that the subtype test in Step (2) above always succeeds:
257+
* If `X` is of the form `_ >: L <: H`, instantiate `ti := H` (resp. `L`, `X`) if `variance = 1` (resp. `-1`, `0`).
258+
* Otherwise, instantiate `ti := X`.
258259
* If `P` is a `TypeCapture` `ti`:
259260
* If `X` is of the form `_ >: L <: H`,
260261
* If `scrutIsWidenedAbstract` is `true`, fail as not specific.

0 commit comments

Comments
 (0)