apache / apache/grails-core

Error when add @GrailsCompileStatic annotation to a class with a property called 'attributes'

Open
#14,589 2 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-neo4j
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

When I have a class with a property called 'attributes' and add @GrailsCompileStatic annotation, I have a compile error.

Here is the example class

```
package neo4jSampleApp.core

import grails.compiler.GrailsCompileStatic

@GrailsCompileStatic
class Player extends BaseGraphDomain {

String name
Integer number

List attributes

static belongsTo = [club: Club]

static constraints = {
name nullable: false, blank: false, unique: true
number nullable: false, validator: { (Integer) it > 0 }
attributes nullable: true
}
}
```
This is the error:

```
[Static type checking] - Cannot call neo4jSampleApp.core.Player#attributes(java.util.Map ) with arguments [java.util.LinkedHashMap ]
@ line 18, column 9.
attributes nullable: true
^

1 error

FAILURE: Build failed with an exception.
```

Apparently, the compiler try use attributes() method from DynamicAttributes trait.

[Here is the link to the example app](https://github.com/AmaliaMV/neo4jSampleApp.git)

Contributor guide

Open the contributing guide

Research direction

Start with the example Player class in the linked neo4jSampleApp and reproduce the failure using @GrailsCompileStatic with a property named attributes. Trace the interaction between the attributes constraint, the generated attributes method, and DynamicAttributes; done means the example compiles without the reported static type-checking error.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.