[
https://issues.apache.org/jira/browse/GROOVY-12748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140913#comment-18140913
]
ASF GitHub Bot commented on GROOVY-12748:
-----------------------------------------
codecov-commenter commented on PR #3282:
URL: https://github.com/apache/groovy/pull/3282#issuecomment-6731850366
##
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3282?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 74.4125%. Comparing base
([`bef476a`](https://app.codecov.io/gh/apache/groovy/commit/bef476a7f68296caf6a221f81b047cbbe277c255?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
to head
([`85ed265`](https://app.codecov.io/gh/apache/groovy/commit/85ed2652af5336638aad0ceb2667328104996b58?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/groovy/pull/3282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #3282 +/- ##
==================================================
- Coverage 74.4215% 74.4125% -0.0091%
+ Complexity 44470 44466 -4
==================================================
Files 1699 1699
Lines 151307 151308 +1
Branches 28867 28866 -1
==================================================
- Hits 112605 112592 -13
- Misses 28394 28403 +9
- Partials 10308 10313 +5
```
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/3282?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Coverage Δ | |
|---|---|---|
|
[...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/3282?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Ftransform%2Fstc%2FStaticTypeCheckingVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3RyYW5zZm9ybS9zdGMvU3RhdGljVHlwZUNoZWNraW5nVmlzaXRvci5qYXZh)
| `88.0521% <100.0000%> (+0.0024%)` | :arrow_up: |
... and [8 files with indirect coverage
changes](https://app.codecov.io/gh/apache/groovy/pull/3282/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests,
report on failures, and find test suite problems.
- :package: [JS Bundle
Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save
yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
> STC: an implicit-parameter closure is reported ambiguous between functional
> interfaces of different arity when its call is type checked a second time
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12748
> URL: https://issues.apache.org/jira/browse/GROOVY-12748
> Project: Groovy
> Issue Type: Bug
> Reporter: Paul King
> Priority: Major
>
> Under {{@TypeChecked}} / {{@CompileStatic}}, a method overloaded on
> functional interfaces that take different numbers of parameters accepts a
> closure with an implicit parameter: GROOVY-10905 prefers the interface whose
> abstract method takes none or one parameter. When the same call is type
> checked a second time, the preference is lost and the call is reported as
> ambiguous, although nothing about it has changed.
> {code:groovy}
> import java.util.function.*
> class C {
> static String m(Function<Integer, Integer> f) { 'function' }
> static String m(BinaryOperator<Integer> f) { 'binary' }
> }
> @groovy.transform.CompileStatic
> def test() {
> assert C.m { it } == 'function' // fine
> def x = 1
> for (i in 0..1) {
> assert C.m { it } == 'function' // [Static type checking] -
> Reference to method is ambiguous. Cannot choose between [java.lang.String
> C#m(java.util.function.Function<java.lang.Integer, java.lang.Integer>),
> java.lang.String C#m(java.util.function.BinaryOperator<java.lang.Integer>)]
> x = 'a'
> }
> }
> test()
> {code}
> Dynamic Groovy chooses {{Function}} in every case.
> h3. When a call is checked again
> * the body of a {{for}} or {{while}} loop, or of a closure, in which a
> variable changes type, is checked a second time;
> * a method that is not found on the result of the call, e.g. {{C.m \{ it
> \}.length()}}, makes the type checker check the call again while looking for
> a property of that name. The expected error (_Cannot find matching method
> java.lang.Object#length()_) is then accompanied by the misleading ambiguity
> error.
> h3. Cause
> The first time the call is checked, the closure has not been visited yet, and
> {{StaticTypeCheckingVisitor.getType}} builds its type with
> {{CLOSURE_ARGUMENTS}} metadata giving its parameter count (-1 for an implicit
> parameter), which {{StaticTypeCheckingSupport.getDistance}} uses to prefer
> the matching interface. Visiting the closure then stores {{Closure<R>}} as
> its inferred type, without that metadata, and {{getType}} returns the stored
> type from then on. Without the parameter count, both overloads are at the
> same distance.
> Closures with declared parameters and method references are not affected on
> master, as the arity check added by GROOVY-10714 / GROOVY-11010 is recomputed
> every time; before that, a closure with declared parameters failed in the
> same way inside a loop.
> h3. Versions
> Seen in 5.1.3 and 6.0.0. 4.0.33 does not have the GROOVY-10905 preference and
> reports such calls as ambiguous even the first time.
> h3. Fix
> Store the parameter count on the closure's inferred type too, so that it is
> used however often the call is checked.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)