diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-11-15 16:48:03 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-11-16 18:08:53 -0800 |
commit | 32c57329a6cb7ff1fa479a1fce884b8166f3fc50 (patch) | |
tree | bf692f26236b210a4280c9cb1dbd20b221b1fd8c /src | |
parent | ea87ecbe818f7445156d6c2548e429a8ca54595d (diff) | |
download | scala-32c57329a6cb7ff1fa479a1fce884b8166f3fc50.tar.gz scala-32c57329a6cb7ff1fa479a1fce884b8166f3fc50.tar.bz2 scala-32c57329a6cb7ff1fa479a1fce884b8166f3fc50.zip |
SI-6624 set info of case pattern binder to help find case field accessors
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
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala index 5beba77155..938866deef 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala @@ -417,7 +417,17 @@ 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 + /* TODO: uncomment when `settings.developer` and `devWarning` become available + if (settings.developer.value && !(patBinder.info =:= extractor.paramType)) + devWarning(s"resetting info of $patBinder: ${patBinder.info} to ${extractor.paramType}") + */ + (Nil, patBinder setInfo extractor.paramType) + } withSubPats(typeTestTreeMaker :+ extractor.treeMaker(patBinderOrCasted, pos), extractor.subBindersAndPatterns: _*) } |