apache / apache/grails-core

@GrailsCompileStatic doesn't allow constraint on @Lazy property

Open
#11,377 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Thanks for reporting an issue for Grails framework, please review the task list below before submitting the
issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/grails) or Slack (http://slack-signup.grails.org). DO NOT use the issue tracker to ask questions.

### Task List

- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### Steps to Reproduce

Add constraint to a `@Lazy` property:

```groovy
@GrailsCompileStatic
class TestCommand implements Validateable {

@Lazy
String someProperty = null

static constraints = {
someProperty nullable:false
}

}
```

### Expected Behaviour

Code should compile. Constraint should work.

### Actual Behaviour

Code won't compile:

```
[Static type checking] - Cannot find matching method TestCommand#someProperty(java.util.LinkedHashMap ) Please check if the declared type is correct and if the method exists.
```

Code works as expected without `@GrailsCompileStatic`

Would it be possible to support this?

Maybe by adding `|| receiver.getProperty(name)` [here](https://github.com/grails/grails-core/blob/master/grails-core/src/main/groovy/org/grails/compiler/ValidateableTypeCheckingExtension.groovy#L62)?

### Environment Information

- **Operating System**: macOS 10.14.5
- **Grails Version:** 3.3.10
- **JDK Version:** 1.8.0_192

### Example Application

https://github.com/felixscheinost/lazy-validateable

Contributor guide

Open the contributing guide

Research direction

Start in grails-core/src/main/groovy/org/grails/compiler/ValidateableTypeCheckingExtension.groovy around line 62 and review the linked lazy-validateable example. Reproduce the @GrailsCompileStatic class with an @Lazy property and nullable constraint; done means it compiles and the constraint works as it does without @GrailsCompileStatic.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.