[ 
https://issues.apache.org/jira/browse/GROOVY-12689?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137773#comment-18137773
 ] 

ASF GitHub Bot commented on GROOVY-12689:
-----------------------------------------

codecov-commenter commented on PR #3208:
URL: https://github.com/apache/groovy/pull/3208#issuecomment-6623466176

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3208?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 `87.50000%` with `1 line` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 74.1497%. Comparing base 
([`9a1a0d0`](https://app.codecov.io/gh/apache/groovy/commit/9a1a0d0ccbc9a1eacd85cbbd408374f6c7f41fc8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`d0729a5`](https://app.codecov.io/gh/apache/groovy/commit/d0729a591abb61efbaa6f963352e1f66c413b10d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 3 commits behind head on master.
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3208?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[...ovy/groovy/typecheckers/FormatStringChecker.groovy](https://app.codecov.io/gh/apache/groovy/pull/3208?src=pr&el=tree&filepath=subprojects%2Fgroovy-typecheckers%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Ftypecheckers%2FFormatStringChecker.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LXR5cGVjaGVja2Vycy9zcmMvbWFpbi9ncm9vdnkvZ3Jvb3Z5L3R5cGVjaGVja2Vycy9Gb3JtYXRTdHJpbmdDaGVja2VyLmdyb292eQ==)
 | 87.5000% | [1 Missing :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/3208?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>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/3208/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/3208?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3208        +/-   ##
   ==================================================
   - Coverage     74.1518%   74.1497%   -0.0022%     
   + Complexity      43728      43725         -3     
   ==================================================
     Files            1692       1692                
     Lines          149527     149530         +3     
     Branches        28360      28360                
   ==================================================
   - Hits           110877     110876         -1     
   - Misses          28438      28444         +6     
   + Partials        10212      10210         -2     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3208?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[...ovy/groovy/typecheckers/FormatStringChecker.groovy](https://app.codecov.io/gh/apache/groovy/pull/3208?src=pr&el=tree&filepath=subprojects%2Fgroovy-typecheckers%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Ftypecheckers%2FFormatStringChecker.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LXR5cGVjaGVja2Vycy9zcmMvbWFpbi9ncm9vdnkvZ3Jvb3Z5L3R5cGVjaGVja2Vycy9Gb3JtYXRTdHJpbmdDaGVja2VyLmdyb292eQ==)
 | `80.0000% <87.5000%> (+1.8978%)` | :arrow_up: |
   
   ... and [14 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3208/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>




> FormatStringChecker fails inside the compiler when an argument's type is 
> declared in the same source
> ----------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12689
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12689
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> With {{groovy.typecheckers.FormatStringChecker}} enabled, a format call with 
> a non-constant argument whose static type is declared in the same compilation 
> unit aborts the compilation with a {{GroovyBugError}}. A plain class is 
> enough, and so is an enum, a record, an anonymous class, an array of such a 
> type, or {{this}} inside the checked class. The conversion does not matter: 
> {{%s}} fails too.
> {{Show.groovy}} and {{ShowColor.groovy}}:
> {code:groovy}
> import groovy.transform.TypeChecked
> class Foo {}
> @TypeChecked(extensions = 'groovy.typecheckers.FormatStringChecker')
> String show() {
>     String.format('%s', new Foo())
> }
> {code}
> {code:groovy}
> import groovy.transform.TypeChecked
> enum Color { RED, GREEN }
> @TypeChecked(extensions = 'groovy.typecheckers.FormatStringChecker')
> String show() {
>     String.format('%s', Color.RED)
> }
> {code}
> {code:sh}
> groovyc --check --error-format=short Show.groovy
> groovyc --check --error-format=short ShowColor.groovy
> {code}
> Actual, for {{Show.groovy}}: exit 1 and
> {code:text}
> >>> a serious error occurred: BUG! exception in phase 'instruction selection' 
> >>> in source unit 'Show.groovy' ClassNode#getTypeClass for Foo called before 
> >>> the type class is set
> >>> stacktrace:
> BUG! exception in phase 'instruction selection' in source unit 'Show.groovy' 
> ClassNode#getTypeClass for Foo called before the type class is set
>       at org.codehaus.groovy.ast.ClassNode.getTypeClass(ClassNode.java:1987)
>       at 
> groovy.typecheckers.FormatStringChecker$1$_checkFormatStringTypes_closure5.doCall(FormatStringChecker.groovy:184)
>       ...
>       at 
> groovy.typecheckers.FormatStringChecker$1.checkFormatStringTypes(FormatStringChecker.groovy:163)
>       at 
> groovy.typecheckers.FormatStringChecker$1.checkFormatterMethod(FormatStringChecker.groovy:156)
>       at 
> groovy.typecheckers.FormatStringChecker$1.visitMethodCallExpression(FormatStringChecker.groovy:122)
>       ...
>       at 
> org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.afterVisitMethod(GroovyTypeCheckingExtensionSupport.java:427)
>       ...
> {code}
> {{ShowColor.groovy}} fails the same way with {{ClassNode#getTypeClass for 
> Color called before the type class is set}}. The smallest form needs no 
> second type:
> {code:groovy}
> @groovy.transform.TypeChecked(extensions = 
> 'groovy.typecheckers.FormatStringChecker')
> class Main {
>     String show() { String.format('%s', this) }
> }
> {code}
> It fails with {{ClassNode#getTypeClass for Main called before the type class 
> is set}}. The same happens when the checker is applied through 
> {{CompilerConfiguration}}:
> {code:groovy}
> import groovy.transform.TypeChecked
> import org.codehaus.groovy.control.CompilerConfiguration
> import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
> def config = new CompilerConfiguration()
> config.addCompilationCustomizers(new ASTTransformationCustomizer(
>         [extensions: 'groovy.typecheckers.FormatStringChecker'], TypeChecked))
> new GroovyShell(config).evaluate('''
>     class Foo {}
>     String.format('%s', new Foo())
> ''')
> {code}
> {code:text}
> org.codehaus.groovy.GroovyBugError: BUG! exception in phase 'instruction 
> selection' in source unit 'Script1.groovy' ClassNode#getTypeClass for Foo 
> called before the type class is set
> {code}
> Expected: these sources compile. They do when {{Foo}} is compiled first and 
> put on the class path: {{groovyc --check}} of the same checked method then 
> exits 0. A real mismatch should still be reported, for example 
> {{IllegalFormatConversion: d != Foo}} for {{String.format('%d', new Foo())}}. 
> That is what the checker reports for a precompiled {{Foo}} or for 
> {{java.util.UUID}}.
> When the checked code also declares an enum or a record, this error hides the 
> one described in GROOVY-12688. The two have separate causes.
> Affected versions: 6.0.0, 6.0.0-beta-1, 5.0.8 and 5.0.0 fail the same way, 
> and so does current master (7.0.0-SNAPSHOT at 5e9212ce1e).
> Cause: when a format call's arguments are not all constants, 
> {{checkFormatStringTypes}} takes the runtime class of each argument's static 
> type ({{getWrapper(getType(arg)).typeClass}}, line 184) and compares it with 
> {{Class}} objects. A type compiled in the same compilation unit has no 
> runtime class yet, so {{ClassNode#getTypeClass}} throws. The class is taken 
> before the conversion is looked at, which is why {{%s}} fails as well. 
> Because {{GroovyBugError}} is an {{Error}}, it escapes the extension's error 
> handling and ends the compilation.
> A fix that works: compare the argument's {{ClassNode}} with the 
> {{ClassHelper}} types, and use 
> {{StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf}} for the 
> date/time check, so that types from the same source are checked like 
> precompiled ones. A pull request with regression tests follows.
> Impact: FormatStringChecker was graduated to stable for 6.0.0 (GROOVY-12039). 
> Checked code that passes an instance of one of its own types to a format 
> method, including {{this}} or one of its own enum constants, cannot be 
> compiled with it. Workaround: compile those types separately, or leave 
> FormatStringChecker off for such sources.
> Environment: Groovy 6.0.0 on BellSoft JDK 21.0.12, macOS 26.5 (arm64); 
> reproduced on master at 5e9212ce1e with JDK 21.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to