You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "codeconsole (via GitHub)" <gi...@apache.org> on 2026/06/05 18:42:35 UTC

[PR] Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

codeconsole opened a new pull request, #15720:
URL: https://github.com/apache/grails-core/pull/15720

   ## What
   
   `CriteriaTypeCheckingExtension` exists in grails-core but is **not registered** in `@GrailsCompileStatic`'s extension list, and `isCriteriaCall` only recognizes the `Domain.withCriteria { … }` / `Domain.createCriteria()` forms (closure as the direct argument). The chained `Domain.createCriteria().<terminal> { … }` form — where the closure is the argument to a terminal called *on the builder* — is never matched, so a criteria scope is never opened for it.
   
   ## Why it matters
   
   Most chained terminals (`list`, `listDistinct`, `get`, `scroll`) still type-check today because `BuildableCriteria` declares them with a `Closure` parameter and `@DelegatesTo` resolves the closure body. But `count(Closure)` is **not** declared on `BuildableCriteria`, so:
   
   ```groovy
   @GrailsCompileStatic
   class Foo {
       def c() { Person.createCriteria().count { eq 'name', 'Anakin' } }
   }
   ```
   
   fails static compilation on stock 8.0.x:
   
   ```
   [Static type checking] - Cannot find matching method
   org.grails.datastore.mapping.query.api.BuildableCriteria#count(groovy.lang.Closure)
   ```
   
   forcing a `@CompileDynamic` escape hatch.
   
   ## Change
   
   1. Extend `isCriteriaCall` to also open a criteria scope when the call is a terminal (`list`, `listDistinct`, `get`, `count`, `scroll`) chained directly on `Domain.createCriteria()`. Registration alone is not enough — the `createCriteria()` scope is exited (via `afterMethodCall`) before the terminal call is visited, so the terminal needs to be recognized in its own right.
   2. Add `org.grails.compiler.CriteriaTypeCheckingExtension` to the `@CompileStatic(extensions=[…])` list on `@GrailsCompileStatic`.
   
   ## Test
   
   Adds `'Test compiling a class which invokes a chained createCriteria() terminal on a domain class'` to `GrailsCompileStaticCompilationErrorsSpec`, covering all six chained terminals. It **fails on stock 8.0.x** (on the `count` terminal) and **passes with this change**. The existing `GRAILS-11255` criteria spec continues to pass.
   
   ## Scope / limits
   
   The extension makes the *direct children* of the criteria closure dynamic. Deeply nested builder closures (e.g. `projections { property '…' }`) and post-processing that indexes the result (`withCriteria { … }[0]`) still require `@CompileDynamic` — out of scope here.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.x Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole merged PR #15720:
URL: https://github.com/apache/grails-core/pull/15720


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#discussion_r3399300843


##########
grails-core/src/main/groovy/grails/compiler/GrailsCompileStatic.groovy:
##########
@@ -33,5 +33,6 @@ import groovy.transform.CompileStatic
                            'org.grails.compiler.WhereQueryTypeCheckingExtension',
                            'org.grails.compiler.DynamicFinderTypeCheckingExtension',
                            'org.grails.compiler.DomainMappingTypeCheckingExtension',
+                           'org.grails.compiler.CriteriaTypeCheckingExtension',

Review Comment:
   Added in b10f36fae9. The TCK now executes criteria queries that were compiled with `@GrailsCompileStatic`, covering both dispatch paths the extension produces: statically-resolved `Criteria` API calls and the dynamic fallback (`projections`, `min`/`countDistinct`/`property`, `maxResults`, and the chained `count { }` terminal, which is not declared on `BuildableCriteria`). Verified green against the in-memory, Hibernate 5, Hibernate 7, and MongoDB implementations locally.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on code in PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#discussion_r3391931330


##########
grails-core/src/main/groovy/grails/compiler/GrailsCompileStatic.groovy:
##########
@@ -33,5 +33,6 @@ import groovy.transform.CompileStatic
                            'org.grails.compiler.WhereQueryTypeCheckingExtension',
                            'org.grails.compiler.DynamicFinderTypeCheckingExtension',
                            'org.grails.compiler.DomainMappingTypeCheckingExtension',
+                           'org.grails.compiler.CriteriaTypeCheckingExtension',

Review Comment:
   To change the default, we need to expand the test coverage so that there are tests in the TCK - this way we know we haven't broken it in hibernate 7.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.x Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#issuecomment-4745452747

   ## ✅ All tests passed ✅
   
   🏷️ Commit: f4fc250d67126d0055b761fb7ff6b1e1989b58a6
   ▶️ Tests:  37210 executed
   ⚪️ Checks: 46/46 completed
   
   ---
   _Learn more about TestLens at [testlens.app](https://testlens.app)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.x Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#issuecomment-4723958135

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 34854cbfc114166299c610f3f8136bac0dd1ad60
   ▶️ Tests:  27039 executed
   ⚪️ Checks: 43/43 completed
   
   ---
   _Learn more about TestLens at [testlens.app](https://testlens.app)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#issuecomment-4634930339

   ## ✅ All tests passed ✅
   
   🏷️ Commit: c1410a5ffd23e9bf945280785681ab219eb65a03
   ▶️ Tests:  11079 executed
   ⚪️ Checks: 43/43 completed
   
   ---
   _Learn more about TestLens at [testlens.app](https://testlens.app)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.x Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#issuecomment-4733266489

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 1a98e99f6c7fe7083b83150ed188c2c568d018ca
   ▶️ Tests:  25040 executed
   ⚪️ Checks: 43/43 completed
   
   ---
   _Learn more about TestLens at [testlens.app](https://testlens.app)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#issuecomment-4685461217

   ## 🚨 TestLens detected 1 failed test 🚨
   
   Here is what you can do:
   
   1) Inspect the test failures carefully.
   2) If you are convinced that some of the tests are flaky, you can mute them below.
   3) Finally, trigger a rerun by checking the rerun checkbox.
   
   ### Test Summary
   
   | Check | Project/Task | Test | Runs |
   |---|---|---|---|
   | [CI / Functional Tests \(Java 21, indy\=false\)](https://github.com/apache/grails-core/actions/runs/27378112529/job/80907593729?pr=15720) | :grails-test-examples-scaffolding:integrationTest | UserControllerSpec > User list | ❌ |
   
   🏷️ Commit: b10f36fae917292f2416cd791e5acd16d42f7bd1
   ▶️ Tests:  3546 executed
   🟡 Checks: 32/39 completed
   
   ### Test Failures
   
   <details>
   
   <summary><strong>UserControllerSpec > User list</strong> (:grails-test-examples-scaffolding:integrationTest in <a href="https://github.com/apache/grails-core/actions/runs/27378112529/job/80907593729?pr=15720">CI / Functional Tests (Java 21, indy=false)</a>)</summary>
   
   ```
   geb.waiting.WaitTimeoutException: condition did not pass in 10 seconds (failed with exception)
   	at geb.waiting.Wait.waitFor(Wait.groovy:128)
   	at geb.waiting.PotentiallyWaitingExecutor.execute(PotentiallyWaitingExecutor.groovy:31)
   	at geb.Page.verifyThisPageAtOnly(Page.groovy:424)
   	at geb.Page.getAtVerificationResult(Page.groovy:217)
   	at geb.Page.verifyAt(Page.groovy:188)
   	at geb.Browser.doAt(Browser.groovy:1208)
   	at geb.Browser.at(Browser.groovy:410)
   	at geb.Browser.to(Browser.groovy:566)
   	at geb.Browser.to(Browser.groovy:543)
   	at geb.Browser.to(Browser.groovy:532)
   	at grails.plugin.geb.support.delegate.BrowserDelegate$Trait$Helper.to(BrowserDelegate.groovy:160)
   	at com.example.UserControllerSpec.User list(UserControllerSpec.groovy:46)
   Caused by: Assertion failed: 
   
   title == pageTitle
   |     |  |
   |     |  'User List'
   |     false
   'Please sign in'
   
   	at com.example.pages.UserListPage._clinit__closure1(UserListPage.groovy:28)
   	at com.example.pages.UserListPage._clinit__closure1(UserListPage.groovy)
   	at geb.waiting.Wait.waitFor(Wait.groovy:117)
   	... 11 more
   ```
   
   </details>
   
   ### Muted Tests
   > [!NOTE]
   > Checks are currently running using the configuration below.
   
   Select tests to mute in this pull request:
   
   🔲 UserControllerSpec > User list <!-- uniqueId=[engine:spock]/[spec:com.example.UserControllerSpec]/[feature:$spock_feature_1_0] -->
   
   Reuse successful test results:
   
   🔲 ♻️ Only rerun the tests that failed or were muted before
   
   Click the checkbox to trigger a rerun:
   
   🔲 **Rerun jobs**
   
   ---
   _Learn more about TestLens at [testlens.app](https://testlens.app)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#issuecomment-4675233891

   <!-- Bito Reply -->
   The pull request already includes a new test case, 'Test compiling a class which invokes a chained createCriteria() terminal on a domain class', within `GrailsCompileStaticCompilationErrorsSpec.groovy`. This test verifies that chained `createCriteria()` calls (e.g., `.list`, `.get`, `.count`) are correctly type-checked under `@GrailsCompileStatic`. If further TCK (Technology Compatibility Kit) coverage is required, you should add similar integration tests to the dedicated TCK test suite modules, as the current tests are located in the `grails-test-suite-uber` module.
   
   **grails-test-suite-uber/src/test/groovy/grails/compiler/GrailsCompileStaticCompilationErrorsSpec.groovy**
   ```
   void 'Test compiling a class which invokes a chained createCriteria() terminal on a domain class'() {
           given:
           def gcl = new GroovyClassLoader()
   
           when: 'the criteria builder closure is the argument to a terminal chained directly on createCriteria()'
           def c = gcl.parseClass('''
               package grails.compiler
   
               @GrailsCompileStatic
               class SomeClass {
   
                   def someMethod() {
                       Person.createCriteria().list {
                           cache true
                           eq 'name', 'Anakin'
                       }
                       // ... other terminals
                   }
               }
           '''.stripIndent())
   
           then: 'no errors are thrown'
           c
       }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.x Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#issuecomment-4723373536

   Wired `StaticCompiledCriteriaSpec` into `HibernateSuite` and `Hibernate5Suite` (`34854cbfc1`). The spec had been added to the TCK but wasn't in any `@SelectClasses` suite, so it never ran against a GORM implementation. It now executes against both Hibernate 7 and Hibernate 5 — 9 tests each, asserting real query results — covering both dispatch paths the extension produces: static delegate dispatch (`eq`/`like`/`or`/`order`) and the dynamic fallback (projections, `maxResults`, `count` chained on `createCriteria()`). A regression in either ORM now fails CI.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Register CriteriaTypeCheckingExtension and cover createCriteria().{} closures [grails-core]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #15720:
URL: https://github.com/apache/grails-core/pull/15720#issuecomment-4634486527

   ## [Codecov](https://app.codecov.io/gh/apache/grails-core/pull/15720?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 18.2620%. Comparing base ([`41f9fb9`](https://app.codecov.io/gh/apache/grails-core/commit/41f9fb95278081c8132b3f5d8db3a3c2213c724d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`c1410a5`](https://app.codecov.io/gh/apache/grails-core/commit/c1410a5ffd23e9bf945280785681ab219eb65a03?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/grails-core/pull/15720/graphs/tree.svg?width=650&height=150&src=pr&token=qJrryhpk7u&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/grails-core/pull/15720?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                 Coverage Diff                 @@
   ##                8.0.x     #15720         +/-   ##
   ===================================================
   - Coverage     48.3483%   18.2620%   -30.0864%     
   + Complexity      15104        258      -14846     
   ===================================================
     Files            1870         54       -1816     
     Lines           85459       3176      -82283     
     Branches        14901        527      -14374     
   ===================================================
   - Hits            41318        580      -40738     
   + Misses          37805       2486      -35319     
   + Partials         6336        110       -6226     
   ```
   [see 1816 files with indirect coverage changes](https://app.codecov.io/gh/apache/grails-core/pull/15720/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>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org