From 208a42444a49c0af9250defaaec82fb79800584e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Tue, 6 Feb 2024 10:39:34 +0100 Subject: [PATCH] Match types: fix wildcard captures handling to match intent. As demonstrated by https://github.com/lampepfl/dotty/issues/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. --- content/match-types-spec.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/match-types-spec.md b/content/match-types-spec.md index 6609d93..1624e64 100644 --- a/content/match-types-spec.md +++ b/content/match-types-spec.md @@ -253,8 +253,9 @@ At the top level, `variance = 1` and `scrutIsWidenedAbstract = false`. * If `P` is a `TypeWithoutCapture`: * Do nothing (always succeed). * If `P` is a `WildcardCapture` `ti = _`: - * If `X` is of the form `_ >: L <: H`, instantiate `ti := H` (anything between `L` and `H` would work here), - * Otherwise, instantiate `ti := X`. + * Instantiate `ti` so that the subtype test in Step (2) above always succeeds: + * If `X` is of the form `_ >: L <: H`, instantiate `ti := H` (resp. `L`, `X`) if `variance = 1` (resp. `-1`, `0`). + * Otherwise, instantiate `ti := X`. * If `P` is a `TypeCapture` `ti`: * If `X` is of the form `_ >: L <: H`, * If `scrutIsWidenedAbstract` is `true`, fail as not specific.