Skip to content

Commit 2bb5197

Browse files
committed
hide SIP-67 behaviour behind experimental feature flag
1 parent a029737 commit 2bb5197

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ object Feature:
2828

2929
val dependent = experimental("dependent")
3030
val erasedDefinitions = experimental("erasedDefinitions")
31+
val strictEqualityPatternMatching = experimental("strictEqualityPatternMatching")
3132
val symbolLiterals = deprecated("symbolLiterals")
3233
val saferExceptions = experimental("saferExceptions")
3334
val pureFunctions = experimental("pureFunctions")
@@ -58,6 +59,7 @@ object Feature:
5859
(scala2macros, "Allow Scala 2 macros"),
5960
(dependent, "Allow dependent method types"),
6061
(erasedDefinitions, "Allow erased definitions"),
62+
(strictEqualityPatternMatching, "relaxed CanEqual checks for ADT pattern matching"),
6163
(symbolLiterals, "Allow symbol literals"),
6264
(saferExceptions, "Enable safer exceptions"),
6365
(pureFunctions, "Enable pure functions for capture checking"),

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ case class Mode(val bits: Int) extends AnyVal {
3131
object Mode {
3232
val None: Mode = Mode(0)
3333

34-
private val modeName = new Array[String](32)
34+
private val modeName = new Array[String](33)
3535

3636
def newMode(bit: Int, name: String): Mode = {
3737
modeName(bit) = name
@@ -206,4 +206,7 @@ object Mode {
206206

207207
/** Skip inlining of methods. */
208208
val NoInline: Mode = newMode(31, "NoInline")
209+
210+
/** strictEquality pattern matching (SIP-67) */
211+
val StrictEqualityPatternMatching: Mode = newMode(32, "strictEqualityPatternMatching")
209212
}

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ object Implicits:
8484
def strictEquality(using Context): Boolean =
8585
ctx.mode.is(Mode.StrictEquality) || Feature.enabled(nme.strictEquality)
8686

87+
def strictEqualityPatternMatching(using Context): Boolean =
88+
ctx.mode.is(Mode.StrictEqualityPatternMatching) || Feature.enabled(Feature.strictEqualityPatternMatching)
89+
8790

8891
/** A common base class of contextual implicits and of-type implicits which
8992
* represents a set of references to implicit definitions.
@@ -1065,7 +1068,9 @@ trait Implicits:
10651068
|| locally:
10661069
if strictEquality then
10671070
leftTreeOption.exists: leftTree =>
1068-
leftTree.symbol.flags.isAllOf(Flags.EnumValue) || (leftTree.symbol.flags.isAllOf(Flags.Module | Flags.Case))
1071+
strictEqualityPatternMatching && (
1072+
leftTree.symbol.flags.isAllOf(Flags.EnumValue) || (leftTree.symbol.flags.isAllOf(Flags.Module | Flags.Case))
1073+
)
10691074
else
10701075
(ltp <:< lift(rtp) || rtp <:< lift(ltp))
10711076
}

compiler/test/dotty/tools/dotc/typer/SIP67Tests.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class SIP67Tests extends DottyTest:
1212
def sip67test1: Unit =
1313
val source = """
1414
import scala.language.strictEquality
15+
import scala.language.experimental.strictEqualityPatternMatching
1516
enum Foo:
1617
case Bar
1718
@@ -28,6 +29,7 @@ class SIP67Tests extends DottyTest:
2829
def sip67test2: Unit =
2930
val source = """
3031
import scala.language.strictEquality
32+
import scala.language.experimental.strictEqualityPatternMatching
3133
3234
sealed trait Foo
3335

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ object language:
5050
@compileTimeOnly("`erasedDefinitions` can only be used at compile time in import statements")
5151
object erasedDefinitions
5252

53+
/** Experimental support for relaxed CanEqual checks for ADT pattern matching
54+
*
55+
* @see [[https://github.com/scala/improvement-proposals/pull/97]]
56+
*/
57+
@compileTimeOnly("`strictEqualityPatternMatching` can only be used at compile time in import statements")
58+
object strictEqualityPatternMatching
59+
5360
/** Experimental support for using indentation for arguments
5461
*/
5562
@compileTimeOnly("`fewerBraces` can only be used at compile time in import statements")

0 commit comments

Comments
 (0)