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

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

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

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3236?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.1825%. Comparing base 
([`04b8160`](https://app.codecov.io/gh/apache/groovy/commit/04b8160fd112dc086d0785e25ae2f4e6925ec359?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`db1505a`](https://app.codecov.io/gh/apache/groovy/commit/db1505a9be97d1f39947855d85fb45eb3d33fa37?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>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/3236/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/3236?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3236        +/-   ##
   ==================================================
   + Coverage     74.1763%   74.1825%   +0.0062%     
   - Complexity      43806      43810         +4     
   ==================================================
     Files            1692       1692                
     Lines          149758     149759         +1     
     Branches        28417      28413         -4     
   ==================================================
   + Hits           111085     111095        +10     
   + Misses          28465      28462         -3     
   + Partials        10208      10202         -6     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3236?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[...ain/groovy/groovy/typecheckers/RegexChecker.groovy](https://app.codecov.io/gh/apache/groovy/pull/3236?src=pr&el=tree&filepath=subprojects%2Fgroovy-typecheckers%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Ftypecheckers%2FRegexChecker.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LXR5cGVjaGVja2Vycy9zcmMvbWFpbi9ncm9vdnkvZ3Jvb3Z5L3R5cGVjaGVja2Vycy9SZWdleENoZWNrZXIuZ3Jvb3Z5)
 | `84.0000% <100.0000%> (+2.7919%)` | :arrow_up: |
   
   ... and [8 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3236/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>




> RegexChecker fails inside the compiler on script binding variables
> ------------------------------------------------------------------
>
>                 Key: GROOVY-12706
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12706
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-typecheckers
>    Affects Versions: 5.1.3, 6.0.0
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>
> h2. Problem
> With {{groovy.typecheckers.RegexChecker}} enabled, a script that uses a 
> binding variable (one assigned without {{def}}) in a regex subscript or a 
> {{findGroups}} call makes the compiler fail with a general error, instead of 
> reporting the normal type-checking error for an undeclared variable.
> Reproducer, run with {{groovy --configscript config.groovy subscript.groovy}}:
> {code:groovy|title=config.groovy}
> import groovy.transform.TypeChecked
> withConfig(configuration) {
>     ast(TypeChecked, extensions: 'groovy.typecheckers.RegexChecker')
> }
> {code}
> {code:groovy|title=subscript.groovy}
> finder = 'groovy' =~ /(oo)/
> finder[0]
> {code}
> Actual:
> {noformat}
> General error during canonicalization: No signature of method: 
> getNodeMetaData for class: org.codehaus.groovy.ast.DynamicVariable is 
> applicable for argument types: (String) values: 
> [RegexChecker_INFERRED_GROUP_COUNT]
> {noformat}
> Expected: the same result as without the extension:
> {noformat}
> [Static type checking] - The variable [finder] is undeclared.
> {noformat}
> ||Script||4.0.32||5.0.6||5.1.3||6.0.0||master||
> |{{finder = 'groovy' =~ /(oo)/; finder[0]}}|general error|general 
> error|general error|general error|general error|
> |{{p = ~/(oo)/; 'groovy'.findGroups(p)}}|undeclared (correct)|undeclared 
> (correct)|undeclared (correct)|general error|general error|
> |{{p = ~/(oo)/; p.matcher('groovy')}}|undeclared (correct)|undeclared 
> (correct)|undeclared (correct)|undeclared (correct)|undeclared (correct)|
> |{{m = 'groovy' =~ /(oo)/; m.group(1)}}|undeclared (correct)|undeclared 
> (correct)|undeclared (correct)|undeclared (correct)|undeclared (correct)|
> h2. Cause
> For a binding variable, {{CheckingVisitor.findTargetVariable}} returns an 
> {{org.codehaus.groovy.ast.DynamicVariable}}, which is not an {{ASTNode}} and 
> has no node metadata. RegexChecker reads its group-count metadata from 
> whatever that lookup returns ({{var?.getNodeMetaData(...)}} / 
> {{source?.getNodeMetaData(...)}}), so the dynamic {{getNodeMetaData}} call 
> fails:
> * the {{matcher[...]}} subscript inference in {{beforeVisitMethod}} (present 
> since RegexChecker was added);
> * the {{findGroups}} fallback that takes the group count from a pattern 
> variable (6.0.0 onwards);
> * the {{Pattern.matcher(...)}} propagation and the {{Matcher.group(...)}} 
> check. These are only reached when the variable's type is {{Pattern}} or 
> {{Matcher}}, so they don't fail today. They would once binding variables 
> carry checked types (GROOVY-12462).
> The other checkers in groovy-typecheckers that look up variables 
> (NullChecker, PurityChecker, ModifiesChecker, SqlInjectionChecker) already 
> handle a {{DynamicVariable}} safely.
> h2. Proposed fix
> Treat a lookup result that is not an AST node as an untracked variable: skip 
> the regex metadata reads and writes, and leave the variable to normal type 
> checking. Cover all four lookup sites, including the {{copyRegexMetaData}} 
> helper added by GROOVY-12697.
> h2. Tests
> * Each row of the table above reports only the undeclared-variable error, 
> with no general error.
> * A regex declared with {{def}} in the same script is still checked ({{def m 
> = 'groovy' =~ /(oo)/; m[0][2]}} reports "Invalid group count 2 for regex with 
> 1 group").
> Static compilation of scripts that use binding variables is uncommon today, 
> but GROOVY-12462 (typed binding for REPL hosts) is intended to make it 
> routine, so this should be fixed before that work.



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

Reply via email to