Register CriteriaTypeCheckingExtension and cover createCriteria().<terminal>{} closures#15720
Open
codeconsole wants to merge 1 commit into
Open
Register CriteriaTypeCheckingExtension and cover createCriteria().<terminal>{} closures#15720codeconsole wants to merge 1 commit into
codeconsole wants to merge 1 commit into
Conversation
…rminal>{} closures
CriteriaTypeCheckingExtension existed but was never added to the
@GrailsCompileStatic extension list, and isCriteriaCall only recognized the
Domain.withCriteria {} / Domain.createCriteria() forms where the closure is
the direct argument. The chained Domain.createCriteria().<terminal> { } form
(closure as the argument to a terminal called on the builder) was not
matched, so its scope was never opened.
Most chained terminals (list/listDistinct/get/scroll) still type-checked
because BuildableCriteria declares them with a Closure parameter and
@DelegatesTo resolves the closure body. count(Closure) is not declared on
BuildableCriteria, so Domain.createCriteria().count {} failed static
compilation with 'Cannot find matching method BuildableCriteria#count(Closure)'.
Extend isCriteriaCall to also open a criteria scope for a terminal
(list/listDistinct/get/count/scroll) chained directly on createCriteria(),
and register the extension in @GrailsCompileStatic so criteria-builder
closures type-check under static compilation. Adds a test covering all six
chained terminals; count is the case that fails without this change.
git log --oneline -1
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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 🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: c1410a5 Learn more about TestLens at testlens.app. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
CriteriaTypeCheckingExtensionexists in grails-core but is not registered in@GrailsCompileStatic's extension list, andisCriteriaCallonly recognizes theDomain.withCriteria { … }/Domain.createCriteria()forms (closure as the direct argument). The chainedDomain.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 becauseBuildableCriteriadeclares them with aClosureparameter and@DelegatesToresolves the closure body. Butcount(Closure)is not declared onBuildableCriteria, so:fails static compilation on stock 8.0.x:
forcing a
@CompileDynamicescape hatch.Change
isCriteriaCallto also open a criteria scope when the call is a terminal (list,listDistinct,get,count,scroll) chained directly onDomain.createCriteria(). Registration alone is not enough — thecreateCriteria()scope is exited (viaafterMethodCall) before the terminal call is visited, so the terminal needs to be recognized in its own right.org.grails.compiler.CriteriaTypeCheckingExtensionto the@CompileStatic(extensions=[…])list on@GrailsCompileStatic.Test
Adds
'Test compiling a class which invokes a chained createCriteria() terminal on a domain class'toGrailsCompileStaticCompilationErrorsSpec, covering all six chained terminals. It fails on stock 8.0.x (on thecountterminal) and passes with this change. The existingGRAILS-11255criteria 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.