[
https://issues.apache.org/jira/browse/GROOVY-12714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18139743#comment-18139743
]
ASF GitHub Bot commented on GROOVY-12714:
-----------------------------------------
daniellansun opened a new pull request, #3246:
URL: https://github.com/apache/groovy/pull/3246
JIRA: https://issues.apache.org/jira/browse/GROOVY-12714
## Summary
Extends `GenericsJavaCompatibilityTest` with the JLS 4.5.1 / 4.5.2 / 4.10.2
PECS rows that were not already a dedicated case, and aligns `@CompileStatic`
with javac where those cases diverged.
## New tests
- `testPecsContainmentMatrix` — legal containment assignments, including
`List<? super Integer>` to `List<? extends Object>`
- `testPecsTransfer` — `<E> void transfer(List<? extends E>, List<? super
E>)` with an `Integer` producer and a `Number` consumer
- `testPecsContravariantPredicateAndConsumer` — `Predicate<? super
CharSequence>` and `Consumer<? super Number>` accept a more specific value
- `testPecsWildcardExtendsReturn` — a method may return `List<? extends
Number>`; the caller reads `Number`
- `testPecsNegativeReadIntegerFromSuper` /
`testPecsNegativeReadIntegerFromExtends`
- `testPecsNegativeAddDoubleToSuperInteger`
- `testPecsNegativeAssignExtendsToInvariantList` — `List<? extends Number>`
is not a `List<Number>`
- `testPecsNegativeAssignStringListToExtendsNumber`
- `testPecsNegativeAssignExtendsNumberToExtendsInteger`
- `testPecsNegativeAssignSuperIntegerToSuperNumber`
- `testPecsNegativeAssignSuperToExtendsNumber` /
`testPecsNegativeAssignExtendsToSuperInteger`
- `testPecsNegativeTransferWrongPolarity`
## Static type checking
- Capture of `? super T` accepts a concrete element only when it is a
subtype of `T` (`StaticTypeCheckingSupport`).
- `? extends A` is contained in `? extends B` only when `A` is a subtype of
`B`; `? super A` is contained in `? super S` only when `S` is a subtype of `A`
(`GenericsType`).
- Assignment rejects a wildcard stored in a concrete type argument
(`List<Number> = List<? extends Number>`), while a type variable may still
capture a wildcard (`StaticTypeCheckingVisitor`).
Checked with `./gradlew :test --tests
gls.generics.GenericsJavaCompatibilityTest` and
`groovy.transform.stc.GenericsSTCTest`. The oracle is this environment's javac;
the cases follow JLS SE 25 sections 4.5.1, 4.5.2, 4.10.2 and 5.1.10.
> `@CompileStatic` PECS wildcard containment diverges from javac (JLS 4.5.1)
> --------------------------------------------------------------------------
>
> Key: GROOVY-12714
> URL: https://issues.apache.org/jira/browse/GROOVY-12714
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Daniel Sun
> Priority: Major
>
> h2. Problem
> Under {{@CompileStatic}}, Groovy's generics / wildcard containment was more
> permissive than javac for several JLS 4.5.1 PECS cases, including:
> * adding a non-subtype into {{List<? super Integer>}} (e.g. {{add(Double)}})
> * treating {{? extends Number}} as contained in {{? extends Integer}} (and
> the dual lower-bound mistake)
> * assigning a wildcard producer {{List<? extends Number>}} to an invariant
> {{List<Number>}}
> h2. Fix
> Align containment and capture write checks with JLS SE 25 §§4.5.1, 4.5.2,
> 4.10.2, 5.1.10 so {{@CompileStatic}} matches javac.
> h2. Tests
> Extend {{gls.generics.GenericsJavaCompatibilityTest}} with PECS containment /
> transfer / negative cases that both compilers must agree on.
> h2. PR
> https://github.com/apache/groovy/pull/3246
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)