Skip to content
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

unapplySeq extractor pattern with tuple type won't compile for the empty Seq #7039

Closed
scabug opened this issue Jan 29, 2013 · 5 comments
Closed

Comments

@scabug
Copy link

scabug commented Jan 29, 2013

object UnapplySeqTest {
  def unapplySeq(any: Any): Option[(Int, Seq[Int])] = None
}

null match {
  case UnapplySeqTest(5) => println("Matched!")    // shows the error
  case UnapplySeqTest(5, 1) => println("Matched!") // compiles
}

fails to compile with this error:

(the last tuple-component of) the result type of an unapplySeq must be a Seq[_]
  case UnapplySeqTest(5) => println("Matched!")

This is a regression from 2.9.2 probably introduced in ee5721e864.

I tried changing this line to if (productArgs.size == 1) { (v2.10.x branch) because the check should be done on the type of the unapplySeq method IMO. However, this then fails later with this exception:

scala.MatchError: <notype> (of class scala.reflect.internal.Types$NoType$)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTranslation$ExtractorCall.subPatTypes(PatternMatching.scala:642)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTranslation$class.translateExtractorPattern$1(PatternMatching.scala:405)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTranslation$class.translatePattern(PatternMatching.scala:458)
	at scala.tools.nsc.typechecker.PatternMatching$OptimizingMatchTranslator.translatePattern(PatternMatching.scala:132)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTranslation$class.translateCase(PatternMatching.scala:384)
	at scala.tools.nsc.typechecker.PatternMatching$OptimizingMatchTranslator.translateCase(PatternMatching.scala:132)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTranslation$$anonfun$9.apply(PatternMatching.scala:306)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTranslation$$anonfun$9.apply(PatternMatching.scala:306)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.immutable.List.foreach(List.scala:309)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
	at scala.collection.AbstractTraversable.map(Traversable.scala:105)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTranslation$class.translateMatch(PatternMatching.scala:306)
	at scala.tools.nsc.typechecker.PatternMatching$OptimizingMatchTranslator.translateMatch(PatternMatching.scala:132)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTransformer.transform(PatternMatching.scala:90)
	at scala.tools.nsc.typechecker.PatternMatching$MatchTransformer.transform(PatternMatching.scala:85)
	at scala.reflect.internal.Trees$$anonfun$itransform$1.apply(Trees.scala:1221)
	at scala.reflect.internal.Trees$$anonfun$itransform$1.apply(Trees.scala:1220)
	at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:2961)

so there seems to be a deeper problem.

@scabug
Copy link
Author

scabug commented Jan 29, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7039?orig=1
Reporter: @jrudolph
Affected Versions: 2.10.0, 2.11.0-M1

@scabug
Copy link
Author

scabug commented Jan 29, 2013

@jrudolph said:
Changing the line from above to if (productArgs.size == 1) to make the error go away in combination with -Xoldpatmat works.

@scabug
Copy link
Author

scabug commented Jan 29, 2013

@jrudolph said:
A proposal for a fix:

scala/scala#2003

@scabug
Copy link
Author

scabug commented Jan 31, 2013

@retronym said:
Bumping to critical on account of regression status.

@scabug
Copy link
Author

scabug commented Feb 3, 2013

@adriaanm said:
scala/scala#2051

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants