Skip to content

SI-6624 better lookup of case field accessors for case class pattern with complicated type #1638

Merged
merged 1 commit into from Nov 19, 2012

5 participants

@adriaanm
The Scala Programming Language member

(I need to run, but wanted to let the bot build this already -- will assign reviewer etc ASAP)

@adriaanm
The Scala Programming Language member

review by @retronym

@retronym
The Scala Programming Language member

lgtm

@paulp paulp commented on an outdated diff Nov 16, 2012
...ler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -417,7 +417,13 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// (the prefix of the argument passed to the unapply must equal the prefix of the type of the binder)
val treeMaker = TypeTestTreeMaker(patBinder, patBinder, extractor.paramType, extractor.paramType)(pos, extractorArgTypeTest = true)
(List(treeMaker), treeMaker.nextBinder)
- } else (Nil, patBinder)
+ } else {
+ // no type test needed, but the tree maker relies on `patBinderOrCasted` having type `extractor.paramType` (and not just some type compatible with it)
+ // SI-6624 shows this is necessary because apparently patBinder may have an unfortunate type (.decls don't have the case field accessors)
+ // TODO: get to the bottom of this -- I assume it happens when type checking infers a weird type for an unapply call
+ // by going back to the parameterType for the extractor call we get a saner type, so let's just do that for now
+ (Nil, patBinder setInfo extractor.paramType)
+ }
@paulp
paulp added a note Nov 16, 2012

This seems like the kind of hinges-on-a-subtlety place where we would benefit from some logging. If you want to get to the bottom of this faster,

if (settings.developer.value) { // depends on another pull request
  if (!(patBinder.info =:= extractor.paramType))
    devWarning("say something useful...")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@adriaanm adriaanm SI-6624 set info of case pattern binder to help find case field acces…
…sors

sometimes the type checker infers a weird type for a sub-pattern of a case class/extractor pattern
this confuses the pattern matcher and it can't find the case field accessors for the sub-pattern

use the expected argument type of the extractor corresponding to the case class that we're matching
as the info for the sub-pattern binder -- this type more readily admits querying its caseFieldAccessors
32c5732
@adriaanm
The Scala Programming Language member

(the commit was only updated to improve docs/commit message)

@jsuereth jsuereth merged commit 888d0b4 into scala:2.10.0-wip Nov 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.