[
https://issues.apache.org/jira/browse/GROOVY-12481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18130864#comment-18130864
]
ASF GitHub Bot commented on GROOVY-12481:
-----------------------------------------
codecov-commenter commented on PR #3015:
URL: https://github.com/apache/groovy/pull/3015#issuecomment-6363986137
##
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3015?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
Report
:x: Patch coverage is `91.66667%` with `1 line` in your changes missing
coverage. Please review.
:white_check_mark: Project coverage is 72.4415%. Comparing base
([`fa53afa`](https://app.codecov.io/gh/apache/groovy/commit/fa53afab4ff811b7ed93560300cd626d0374842e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
to head
([`7438297`](https://app.codecov.io/gh/apache/groovy/commit/7438297e224ef382bad88821732f39c0ee759d23?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/3015?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Patch % | Lines |
|---|---|---|
|
[...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/3015?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)
| 85.7143% | [0 Missing and 1 partial :warning:
](https://app.codecov.io/gh/apache/groovy/pull/3015?src=pr&el=tree&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/3015?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #3015 +/- ##
==================================================
- Coverage 72.4452% 72.4415% -0.0037%
- Complexity 40687 40691 +4
==================================================
Files 1644 1644
Lines 142897 142907 +10
Branches 26877 26880 +3
==================================================
+ Hits 103522 103524 +2
- Misses 29820 29827 +7
- Partials 9555 9556 +1
```
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/3015?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Coverage Δ | |
|---|---|---|
|
[...sc/StaticTypesMethodReferenceExpressionWriter.java](https://app.codecov.io/gh/apache/groovy/pull/3015?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2Fsc%2FStaticTypesMethodReferenceExpressionWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9zYy9TdGF0aWNUeXBlc01ldGhvZFJlZmVyZW5jZUV4cHJlc3Npb25Xcml0ZXIuamF2YQ==)
| `90.0568% <100.0000%> (+0.7196%)` | :arrow_up: |
|
[...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/3015?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)
| `87.0684% <85.7143%> (-0.0082%)` | :arrow_down: |
... and [9 files with indirect coverage
changes](https://app.codecov.io/gh/apache/groovy/pull/3015/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>
> SC: `this::method` in a static context fails to compile with "Failed to find
> method ... for the type: java.lang.Class<A>"
> -------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12481
> URL: https://issues.apache.org/jira/browse/GROOVY-12481
> Project: Groovy
> Issue Type: Improvement
> Components: Static compilation
> Affects Versions: 5.1.2, 6.0.0
> Reporter: Paul King
> Priority: Major
>
> h2. Description:
> In a static context, `this` is the class itself (a `Class<A>` value). Under
> {{@CompileStatic}}, a method reference with a {{this}} receiver in a static
> method, static initializer or static script method looks for the method on
> {{java.lang.Class}} only, not as a static method of the class. So
> {{this::foo}} fails to compile, although {{A::foo}}, {{this.foo()}} and
> {{this.&foo}} all work. With {{@TypeChecked}} or dynamic compilation,
> {{this::foo}} works.
> {code:groovy}
> import groovy.transform.CompileStatic
> import java.util.function.Supplier
> @CompileStatic
> class A {
> static foo() { 42 }
> static m() {
> Supplier s = this::foo
> s.get()
> }
> }
> assert A.m() == 42
> {code}
> {noformat}
> Failed to find method 'foo()' for the type: java.lang.Class<A>
> {noformat}
> ||Form, in a static method||{{@CompileStatic}}||{{@TypeChecked}}||dynamic||
> |{{this::foo}} (static {{foo()}})|*compile error*|42|42|
> |{{this::bar}} (static {{bar(int)}}, {{Function<Integer,Object>}})|*compile
> error*|works|works|
> |{{this::foo}} in a {{static \{ \}}} initializer|*compile error*|works|works|
> |{{this::foo}} in a static method of a script|*compile error*|works|works|
> |{{this::getSimpleName}} (method of {{java.lang.Class}})|"A"|"A"|"A"|
> |{{A::foo}}|42|42|42|
> |{{this.foo()}}|42|42|42|
> |{{this.&foo}}|42|42|42|
> |{{this::inst}} (instance method {{inst()}})|compile error (same wrong
> message)|{{MissingMethodException}} at runtime|{{MissingMethodException}} at
> runtime|
> Expected: in a static context, {{this::name}} resolves the way
> {{this.name()}} already does under {{@CompileStatic}}: first as a static
> method of the enclosing class, otherwise as a method of {{java.lang.Class}},
> so that {{this::getSimpleName}} keeps working. When neither exists, the error
> should name the enclosing class, not only {{Class<A>}}.
> Cause:
> {{StaticTypesMethodReferenceExpressionWriter.resolveMethodReferenceTarget}}
> treats only a {{ClassExpression}} receiver as a type reference. For any other
> receiver it takes the type from the type chooser, which for {{this}} in a
> static context is {{Class<A>}}. So the lookup runs against
> {{java.lang.Class}} and fails in {{validate}}. Because the error is raised
> during class generation, the type checker has already accepted the code,
> which is why {{@TypeChecked}} compiles it.
> Workaround: use {{A::foo}} or {{this.&foo}}.
> Note: Java rejects this in a static context entirely (and rejects
> this::staticMethod even in an instance context), so there's no Java behaviour
> to match. Groovy accepts both forms dynamically and with @TypeChecked, and
> @CompileStatic accepts the instance-context form, so the static-context case
> is the odd one out.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)