Skip to content

Commit c1cef24

Browse files
committed
Enable betterMatchTypeExtractors in >= 3.6
1 parent fd45847 commit c1cef24

File tree

7 files changed

+57
-13
lines changed

7 files changed

+57
-13
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/Feature.scala

-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ object Feature:
133133

134134
def scala2ExperimentalMacroEnabled(using Context) = enabled(scala2macros)
135135

136-
def betterMatchTypeExtractorsEnabled(using Context) = enabled(betterMatchTypeExtractors)
137-
138136
def quotedPatternsWithPolymorphicFunctionsEnabled(using Context) =
139137
enabled(quotedPatternsWithPolymorphicFunctions)
140138

Diff for: compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+5-7
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, capt, noPrinter}
1515
import config.SourceVersion
1616
import TypeErasure.{erasedLub, erasedGlb}
@@ -3621,10 +3621,8 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
36213621
case MatchTypeCasePattern.TypeMemberExtractor(typeMemberName, capture) =>
36223622
/** Try to remove references to `skolem` from a type in accordance with the spec.
36233623
*
3624-
* If `betterMatchTypeExtractorsEnabled` is enabled then references
3625-
* to `skolem` occuring are avoided by following aliases and
3626-
* singletons, otherwise no attempt made to avoid references to
3627-
* `skolem`.
3624+
* References to `skolem` occuring are avoided by following aliases and
3625+
* singletons.
36283626
*
36293627
* If any reference to `skolem` remains in the result type,
36303628
* `refersToSkolem` is set to true.
@@ -3638,7 +3636,7 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
36383636
case `skolem` =>
36393637
refersToSkolem = true
36403638
tp
3641-
case tp: NamedType if betterMatchTypeExtractorsEnabled =>
3639+
case tp: NamedType =>
36423640
val pre1 = apply(tp.prefix)
36433641
if refersToSkolem then
36443642
tp match
@@ -3656,7 +3654,7 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
36563654
tp.derivedSelect(pre1)
36573655
else
36583656
tp.derivedSelect(pre1)
3659-
case tp: LazyRef if betterMatchTypeExtractorsEnabled =>
3657+
case tp: LazyRef =>
36603658
// By default, TypeMap maps LazyRefs lazily. We need to
36613659
// force it for `refersToSkolem` to be correctly set.
36623660
apply(tp.ref)

Diff for: library/src/scala/runtime/stdLibPatches/language.scala

+1
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. It now has no effect, including when setting an older source version.", since = "3.6")
127128
object betterMatchTypeExtractors
128129

129130
/** Experimental support for quote pattern matching with polymorphic functions

Diff for: tests/neg/mt-deskolemize-2.scala

-2
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:

Diff for: tests/pos/20538.scala

+32
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)]

Diff for: tests/pos/20538b.scala

+19
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

Diff for: tests/pos/mt-deskolemize.scala

-2
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)