Skip to content

Commit c1033c1

Browse files
committed
Enable betterMatchTypeExtractors in >= 3.6
1 parent 97a711c commit c1033c1

File tree

7 files changed

+58
-14
lines changed

7 files changed

+58
-14
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object Feature:
3636
val into = experimental("into")
3737
val namedTuples = experimental("namedTuples")
3838
val modularity = experimental("modularity")
39-
val betterMatchTypeExtractors = experimental("betterMatchTypeExtractors")
39+
val betterMatchTypeExtractors = deprecated("betterMatchTypeExtractors")
4040

4141
def experimentalAutoEnableFeatures(using Context): List[TermName] =
4242
defn.languageExperimentalFeatures
@@ -128,8 +128,6 @@ object Feature:
128128

129129
def scala2ExperimentalMacroEnabled(using Context) = enabled(scala2macros)
130130

131-
def betterMatchTypeExtractorsEnabled(using Context) = enabled(betterMatchTypeExtractors)
132-
133131
/** Is pureFunctions enabled for this compilation unit? */
134132
def pureFunsEnabled(using Context) =
135133
enabledBySetting(pureFunctions)

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import TypeOps.refineUsingParent
1010
import collection.mutable
1111
import util.{Stats, NoSourcePosition, EqHashMap}
1212
import config.Config
13-
import config.Feature.{betterMatchTypeExtractorsEnabled, migrateTo3, sourceVersion}
13+
import config.Feature.{migrateTo3, sourceVersion}
1414
import config.Printers.{subtyping, gadts, matchTypes, noPrinter}
1515
import config.SourceVersion
1616
import TypeErasure.{erasedLub, erasedGlb}
@@ -3481,10 +3481,8 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
34813481
case MatchTypeCasePattern.TypeMemberExtractor(typeMemberName, capture) =>
34823482
/** Try to remove references to `skolem` from a type in accordance with the spec.
34833483
*
3484-
* If `betterMatchTypeExtractorsEnabled` is enabled then references
3485-
* to `skolem` occuring are avoided by following aliases and
3486-
* singletons, otherwise no attempt made to avoid references to
3487-
* `skolem`.
3484+
* References to `skolem` occuring are avoided by following aliases and
3485+
* singletons.
34883486
*
34893487
* If any reference to `skolem` remains in the result type,
34903488
* `refersToSkolem` is set to true.
@@ -3498,7 +3496,7 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
34983496
case `skolem` =>
34993497
refersToSkolem = true
35003498
tp
3501-
case tp: NamedType if betterMatchTypeExtractorsEnabled =>
3499+
case tp: NamedType =>
35023500
val pre1 = apply(tp.prefix)
35033501
if refersToSkolem then
35043502
tp match
@@ -3516,7 +3514,7 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
35163514
tp.derivedSelect(pre1)
35173515
else
35183516
tp.derivedSelect(pre1)
3519-
case tp: LazyRef if betterMatchTypeExtractorsEnabled =>
3517+
case tp: LazyRef =>
35203518
// By default, TypeMap maps LazyRefs lazily. We need to
35213519
// force it for `refersToSkolem` to be correctly set.
35223520
apply(tp.ref)

library/src/scala/runtime/stdLibPatches/language.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ object language:
124124
* @see [[https://github.com/scala/improvement-proposals/pull/84]]
125125
*/
126126
@compileTimeOnly("`betterMatchTypeExtractors` can only be used at compile time in import statements")
127+
@deprecated("The experimental.betterMatchTypeExtractors language import is no longer needed since the feature is now standard", since = "3.6")
127128
object betterMatchTypeExtractors
128129
end experimental
129130

tests/neg/mt-deskolemize-2.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options -language:experimental.betterMatchTypeExtractors
2-
31
trait Expr:
42
type Value
53
object Expr:

tests/pos/20538.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
trait Column:
2+
type T
3+
type F[X]
4+
type Q = F[T]
5+
6+
class varchar extends Column:
7+
type T = String
8+
9+
trait notnull extends Column:
10+
type F[X] = X
11+
12+
object Error:
13+
14+
val firstName = new varchar with notnull
15+
val lastName = new varchar with notnull
16+
17+
val relation = (firstName, lastName)
18+
19+
type RelationTypes = Tuple.InverseMap[relation.type, [X] =>> Column { type Q = X }]
20+
21+
summon[RelationTypes =:= (String, String)]
22+
23+
object Works:
24+
25+
object firstName extends varchar with notnull
26+
object lastName extends varchar with notnull
27+
28+
val relation = (firstName, lastName)
29+
30+
type RelationTypes = Tuple.InverseMap[relation.type, [X] =>> Column { type Q = X }]
31+
32+
summon[RelationTypes =:= (String, String)]

tests/pos/20538b.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait A:
2+
type T
3+
type U = T
4+
5+
trait B extends A:
6+
type T = String
7+
8+
object C extends B
9+
10+
11+
type F[X] = A { type U = X } // works when `U` is replaced with `T`
12+
13+
type InvF[Y] = Y match
14+
case F[x] => x
15+
16+
17+
object Test:
18+
summon[InvF[C.type] =:= String] // ok
19+
summon[InvF[B] =:= String] // error: selector B does not uniquely determine parameter x

tests/pos/mt-deskolemize.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options -language:experimental.betterMatchTypeExtractors
2-
31
trait Expr:
42
type Value
53

0 commit comments

Comments
 (0)