Skip to content

Commit afbd365

Browse files
committed
Allow class members to be matched by type member extractors.
This enables a workaround for the `scala.Enumeration#Value` extractor use case, found notably in json4s.
1 parent cb6b892 commit afbd365

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

content/match-types-spec.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,13 @@ At the top level, `variance = 1` and `scrutIsWidenedAbstract = false`.
270270
* If `T` is a refined type of the form `Base { type Y = ti }`:
271271
* Let `q` be `X` if `X` is a stable type, or the skolem type `∃α:X` otherwise.
272272
* If `q` does not have a type member `Y`, fail as not matching (that implies that `X <:< Base` is false, because `Base` must have a type member `Y` for the pattern to be legal).
273-
* If `q.Y` is abstract or is a class definition, fail as not specific.
274-
* Otherwise, the underlying type definition of `q.Y` is of the form `= U`.
275-
* If `q` is a skolem type `∃α:X` and `U` refers to `α`, fail as not specific.
276-
* Compute `matchPattern(t, U, 0, scrutIsWidenedAbstract)`.
273+
* If `q.Y` is abstract, fail as not specific.
274+
* If `q.Y` is a class member:
275+
* If `q` is a skolem type `∃α:X`, fail as not specific.
276+
* Otherwise, compute `matchPattern(ti, q.Y, 0, scrutIsWidenedAbstract)`.
277+
* Otherwise, the underlying type definition of `q.Y` is of the form `= U`:
278+
* If `q` is a skolem type `∃α:X` and `U` refers to `α`, fail as not specific.
279+
* Otherwise, compute `matchPattern(ti, U, 0, scrutIsWidenedAbstract)`.
277280
* If `T` is a concrete type alias to a type lambda:
278281
* Let `P'` be the beta-reduction of `P`.
279282
* Compute `matchPattern(P', X, variance, scrutIsWidenedAbstract)`.
@@ -303,6 +306,7 @@ These can be categorized as follows:
303306
* 2 libraries with 1 type member extractor each where the `Base` does not contain `Y`; they are both to extract `SomeEnumClass#Value` (from Scala 2 `scala.Enumeration`-based "enums").
304307
* https://github.com/iheartradio/ficus/blob/dcf39d6cd2dcde49b093ba5d1507ca478ec28dac/src/main/scala-3/net/ceedubs/ficus/util/EnumerationUtil.scala#L4-L8
305308
* https://github.com/json4s/json4s/blob/5e0b92a0ca59769f3130e081d0f53089a4785130/ext/src/main/scala-3/org/json4s/ext/package.scala#L4-L8
309+
* the maintainers of `json4s` already accepted a PR with a workaround at https://github.com/json4s/json4s/pull/1347
306310
* 1 library used to have 2 cases of the form `case HKExtractor[f] =>` with `type KHExtractor[f[_, _]] = Base { type Y[a, b] = f[a, b] }`.
307311
* Those used to be at https://github.com/7mind/idealingua-v1/blob/48d35d53ce1c517f9f0d5341871e48749644c105/idealingua-v1/idealingua-v1-runtime-rpc-http4s/src/main/scala-3/izumi/idealingua/runtime/rpc/http4s/package.scala#L10-L15 but they do not exist in the latest version of the library.
308312
* 1 library used to have 1 `&`-type extractor (which "worked" who knows how?):
@@ -314,7 +318,7 @@ These can be categorized as follows:
314318
defined at https://github.com/kory33/s2mc-test/blob/d27c6e85ad292f8a96d7d51af7ddc87518915149/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Generic.scala#L12
315319
It could be replaced by a concrete `class Lock[A](phantom: A)` instead.
316320

317-
The only case for which there exists no workaround that we know of is the extractor for `scala.Enumeration`-based `Value` classes.
321+
All the existing use cases therefore have either already disappeared or have a workaround.
318322

319323
### Other concerns
320324

0 commit comments

Comments
 (0)