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
An improvement to make seq's extractors work for Array and String #7108
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7108?orig=1 |
@paulp said: pt1 match {
// if at least one of the types in an intersection is checkable, use the checkable ones
// this avoids problems as in run/matchonseq.scala, where the expected type is `Coll with scala.collection.SeqLike`
// Coll is an abstract type, but SeqLike of course is not
case RefinedType(ps, _) if ps.length > 1 && (ps exists infer.isCheckable) =>
None
case ptCheckable if infer isUncheckable ptCheckable =>
val classTagExtractor = resolveClassTag(pos, ptCheckable)
if (classTagExtractor != EmptyTree && unapplyMember(classTagExtractor.tpe) != NoSymbol)
Some(classTagExtractor)
else None
case _ => None
} |
@scala/collections should this remain open? |
Secondly, besides being out of scope or binary incompatible, it doesn't seem to work with new collections. It does seem to work if you don't care about the result type I confirmed the 2.12 version extracts a
currently
probably there is an important reason dotty
I was hoping it could infer I couldn't get it to take Firstly,
Thirdly, for completeness, 2.12 warns
|
Forgot to mention
It might be surprising that the view case does not work. I would fail the job interview where they ask to compare Also worth adding that
Maybe I'm not the only person annoyed that with a longish code block, github doesn't let me drag the corner of the edit box bigger; until I add an empty line. |
Firstly, the following codes compile fine while run with exception:
Secondly, there are two useful extractors defined in scala.collection.SeqExtractors.scala. But sadly these two extractors does not work for Array and String, and sometimes we do need these function, especially for String.
I would like the followed codes working as expected:
Here I got an idea to fix the issue by rewriting these two extractors as following:
The text was updated successfully, but these errors were encountered: