New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extractors can't provide Tuples as a single parameter in a match #6111
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6111?orig=1 |
@adriaanm said: This finally gives us a use case for Product1: scala> case class Holder[T](_1: T) extends Product1[T]
defined class Holder
scala> object Foo { def unapply(x: Any): Some[Holder[(Int, Int)]] = Some(Holder((1, 2))) }
defined module Foo
scala> 1 match { case Foo(t) => t }
res0: Holder[(Int, Int)] = Holder((1,2))
// expected (1, 2) as result type, by analogy to the Product2 extractor:
scala> object Foo { def unapply(x: Any): Some[((Int, Int), Any)] = Some(((1, 2), "foo")) }
defined module Foo
scala> 1 match { case Foo(t, _) => t }
res1: (Int, Int) = (1,2) The spec has to be changed, since now it says (specialized to the case for n = 1)
|
@adriaanm said: |
@adriaanm said: |
@adriaanm said: |
`case extractor(extracted) => extracted` yields ``` Warning:(68, 16) class ValueExtractor expects 2 patterns to hold (String, String) but crushing into 2-tuple to fit single pattern (scala/bug#6675) ``` See * scala/bug#6675 * scala/bug#6111
There seems to be an issue when using a generic extractor and which could receive a tuple type. As soon as the generic type parameter in the result type is instantiated with a tuple type, the pattern matcher interprets it as multiple parameters in a match.
This should compile. However, it instead results in the following error:
The work-around to use the
FooHasType
implicit to forceT
to beAny
in the case where it would otherwise be a tuple does not completely solve the issue because then the type info for the components of the tuple gets lost.So, the bottom line: it seems this bug makes it impossible to provide a representation-independent extractor for types such as
Try
.The text was updated successfully, but these errors were encountered: