File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
compiler/src/dotty/tools/dotc/transform/patmat Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -279,7 +279,7 @@ object SpaceEngine {
279279 || unappResult <:< ConstantType (Constant (true )) // only for unapply
280280 || (unapp.symbol.is(Synthetic ) && unapp.symbol.owner.linkedClass.is(Case )) // scala2 compatibility
281281 || unapplySeqTypeElemTp(unappResult).exists // only for unapplySeq
282- || isProductMatch(unappResult, argLen)
282+ || isProductMatch(unappResult.stripNamedTuple , argLen)
283283 || extractorMemberType(unappResult, nme.isEmpty, NoSourcePosition ) <:< ConstantType (Constant (false ))
284284 || unappResult.derivesFrom(defn.NonEmptyTupleClass )
285285 || unapp.symbol == defn.TupleXXL_unapplySeq // Fixes TupleXXL.unapplySeq which returns Some but declares Option
Original file line number Diff line number Diff line change 1+ case class CaseClass (a : Int )
2+
3+ object ProductMatch_CaseClass {
4+ def unapply (int : Int ): CaseClass = CaseClass (int)
5+ }
6+
7+ object ProductMatch_NamedTuple {
8+ def unapply (int : Int ): (a : Int ) = (a = int)
9+ }
10+
11+ object NameBasedMatch_CaseClass {
12+ def unapply (int : Int ): Some [CaseClass ] = Some (CaseClass (int))
13+ }
14+
15+ object NameBasedMatch_NamedTuple {
16+ def unapply (int : Int ): Some [(a : Int )] = Some ((a = int))
17+ }
18+
19+ object Test {
20+ val ProductMatch_CaseClass (a = x1) = 1 // ok, was pattern's type (x1 : Int) is more specialized than the right hand side expression's type Int
21+ val ProductMatch_NamedTuple (a = x2) = 2 // ok, was pattern binding uses refutable extractor `org.test.ProductMatch_NamedTuple`
22+ val NameBasedMatch_CaseClass (a = x3) = 3 // ok, was pattern's type (x3 : Int) is more specialized than the right hand side expression's type Int
23+ val NameBasedMatch_NamedTuple (a = x4) = 4 // ok, was pattern's type (x4 : Int) is more specialized than the right hand side expression's type Int
24+
25+ val CaseClass (a = x5) = CaseClass (5 ) // ok, was pattern's type (x5 : Int) is more specialized than the right hand side expression's type Int
26+ val (a = x6) = (a = 6 ) // ok
27+ }
You can’t perform that action at this time.
0 commit comments