SI-9394 Fix pattern infererence with class tparams in pt #4625
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Constructor patterns must be compatible with the expected type of
the pattern (ie, the scrutinee type). The spec doesn't cover the
whole story here:
http://www.scala-lang.org/files/archive/spec/2.11/08-pattern-matching.html#constructor-patterns
The implementation actually treats monomorphic case classes, like
those in the test case, according the rules for polymorphic case
classes, albeit with an empty type parameter list. As such, we need
to consider another part of the spec that elaborates on type parameter
inference within patterns, and the subsequent static check for
the pattern conforming to the expected type:
http://www.scala-lang.org/files/archive/spec/2.11/08-pattern-matching.html#type-parameter-inference-in-patterns
This "otherwise" corresponds to
inferForApproxPt
within:https://github.com/scala/scala/blob/v2.11.6/src/compiler/scala/tools/nsc/typechecker/Infer.scala#L1063-L1085
This substitutes free type parameters within the expected type
with wildcard types. However, class type parameters were being
excluded from this due to the line of code that this commit removes.
I traced the
owner.isTerm
condition back to f9e5afd.I don't understand the intent; and the tests are still passing.
I have also updated the spec to replace the too-narrow description
of pattern inference in the "constructor patterns" section with a link
to the more up-to-date description in the "pattern inference"
section, and to explain that mono- and polymorphic case classes
are treated uniformly when it comes to checking conformance to the
expected type.