File tree Expand file tree Collapse file tree 5 files changed +21
-2
lines changed
test/dotty/tools/dotc/typer
library/src/scala/runtime/stdLibPatches Expand file tree Collapse file tree 5 files changed +21
-2
lines changed Original file line number Diff line number Diff 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" ),
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ case class Mode(val bits: Int) extends AnyVal {
3131object 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}
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments