From 78fe701994af29d559744ee1ec8ea005f813c45c Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 15 Jul 2024 13:37:14 +0200 Subject: [PATCH] Enable betterMatchTypeExtractors in >= 3.6 --- .../src/dotty/tools/dotc/config/Feature.scala | 4 +-- .../dotty/tools/dotc/core/TypeComparer.scala | 12 +++---- .../runtime/stdLibPatches/language.scala | 1 + tests/neg/mt-deskolemize-2.scala | 2 -- tests/pos/20538.scala | 32 +++++++++++++++++++ tests/pos/20538b.scala | 19 +++++++++++ tests/pos/mt-deskolemize.scala | 2 -- 7 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 tests/pos/20538.scala create mode 100644 tests/pos/20538b.scala diff --git a/compiler/src/dotty/tools/dotc/config/Feature.scala b/compiler/src/dotty/tools/dotc/config/Feature.scala index fa82f14a81fe..a9fc2a7603df 100644 --- a/compiler/src/dotty/tools/dotc/config/Feature.scala +++ b/compiler/src/dotty/tools/dotc/config/Feature.scala @@ -36,7 +36,7 @@ object Feature: val into = experimental("into") val namedTuples = experimental("namedTuples") val modularity = experimental("modularity") - val betterMatchTypeExtractors = experimental("betterMatchTypeExtractors") + val betterMatchTypeExtractors = deprecated("betterMatchTypeExtractors") val quotedPatternsWithPolymorphicFunctions = experimental("quotedPatternsWithPolymorphicFunctions") val betterFors = experimental("betterFors") @@ -133,8 +133,6 @@ object Feature: def scala2ExperimentalMacroEnabled(using Context) = enabled(scala2macros) - def betterMatchTypeExtractorsEnabled(using Context) = enabled(betterMatchTypeExtractors) - def quotedPatternsWithPolymorphicFunctionsEnabled(using Context) = enabled(quotedPatternsWithPolymorphicFunctions) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 0f74ca40843b..646874a7e5c1 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -10,7 +10,7 @@ import TypeOps.refineUsingParent import collection.mutable import util.{Stats, NoSourcePosition, EqHashMap} import config.Config -import config.Feature.{betterMatchTypeExtractorsEnabled, migrateTo3, sourceVersion} +import config.Feature.{migrateTo3, sourceVersion} import config.Printers.{subtyping, gadts, matchTypes, capt, noPrinter} import config.SourceVersion import TypeErasure.{erasedLub, erasedGlb} @@ -3621,10 +3621,8 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) { case MatchTypeCasePattern.TypeMemberExtractor(typeMemberName, capture) => /** Try to remove references to `skolem` from a type in accordance with the spec. * - * If `betterMatchTypeExtractorsEnabled` is enabled then references - * to `skolem` occuring are avoided by following aliases and - * singletons, otherwise no attempt made to avoid references to - * `skolem`. + * References to `skolem` occuring are avoided by following aliases and + * singletons. * * If any reference to `skolem` remains in the result type, * `refersToSkolem` is set to true. @@ -3638,7 +3636,7 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) { case `skolem` => refersToSkolem = true tp - case tp: NamedType if betterMatchTypeExtractorsEnabled => + case tp: NamedType => val pre1 = apply(tp.prefix) if refersToSkolem then tp match @@ -3656,7 +3654,7 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) { tp.derivedSelect(pre1) else tp.derivedSelect(pre1) - case tp: LazyRef if betterMatchTypeExtractorsEnabled => + case tp: LazyRef => // By default, TypeMap maps LazyRefs lazily. We need to // force it for `refersToSkolem` to be correctly set. apply(tp.ref) diff --git a/library/src/scala/runtime/stdLibPatches/language.scala b/library/src/scala/runtime/stdLibPatches/language.scala index 3d71c0da1481..c02fa9cd5ac4 100644 --- a/library/src/scala/runtime/stdLibPatches/language.scala +++ b/library/src/scala/runtime/stdLibPatches/language.scala @@ -124,6 +124,7 @@ object language: * @see [[https://github.com/scala/improvement-proposals/pull/84]] */ @compileTimeOnly("`betterMatchTypeExtractors` can only be used at compile time in import statements") + @deprecated("The experimental.betterMatchTypeExtractors language import is no longer needed since the feature is now standard", since = "3.6") object betterMatchTypeExtractors /** Experimental support for quote pattern matching with polymorphic functions diff --git a/tests/neg/mt-deskolemize-2.scala b/tests/neg/mt-deskolemize-2.scala index 90d506a42e6f..505e47637ac4 100644 --- a/tests/neg/mt-deskolemize-2.scala +++ b/tests/neg/mt-deskolemize-2.scala @@ -1,5 +1,3 @@ -//> using options -language:experimental.betterMatchTypeExtractors - trait Expr: type Value object Expr: diff --git a/tests/pos/20538.scala b/tests/pos/20538.scala new file mode 100644 index 000000000000..a03bf98f6ac3 --- /dev/null +++ b/tests/pos/20538.scala @@ -0,0 +1,32 @@ +trait Column: + type T + type F[X] + type Q = F[T] + +class varchar extends Column: + type T = String + +trait notnull extends Column: + type F[X] = X + +object Error: + + val firstName = new varchar with notnull + val lastName = new varchar with notnull + + val relation = (firstName, lastName) + + type RelationTypes = Tuple.InverseMap[relation.type, [X] =>> Column { type Q = X }] + + summon[RelationTypes =:= (String, String)] + +object Works: + + object firstName extends varchar with notnull + object lastName extends varchar with notnull + + val relation = (firstName, lastName) + + type RelationTypes = Tuple.InverseMap[relation.type, [X] =>> Column { type Q = X }] + + summon[RelationTypes =:= (String, String)] diff --git a/tests/pos/20538b.scala b/tests/pos/20538b.scala new file mode 100644 index 000000000000..d6d176f8a10d --- /dev/null +++ b/tests/pos/20538b.scala @@ -0,0 +1,19 @@ +trait A: + type T + type U = T + +trait B extends A: + type T = String + +object C extends B + + +type F[X] = A { type U = X } // works when `U` is replaced with `T` + +type InvF[Y] = Y match + case F[x] => x + + +object Test: + summon[InvF[C.type] =:= String] // ok + summon[InvF[B] =:= String] // error: selector B does not uniquely determine parameter x diff --git a/tests/pos/mt-deskolemize.scala b/tests/pos/mt-deskolemize.scala index abd61d9d55e6..34f38289b24d 100644 --- a/tests/pos/mt-deskolemize.scala +++ b/tests/pos/mt-deskolemize.scala @@ -1,5 +1,3 @@ -//> using options -language:experimental.betterMatchTypeExtractors - trait Expr: type Value