Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GROOVY-11508: change exception to detailed warning #2117

Conversation

jamesfredley
Copy link

https://issues.apache.org/jira/browse/GROOVY-11508

This PR converts the RuntimeParserException, which stops compilation, to a more detailed warning about using a Trait or Interface with more than one generic type parameter via inheritance.

Resolves grails/grails-data-mapping#1811 which is a significant open issue for the Groovy 3.0.x to 4.0.x upgrade in preparation for Grails 7. Grails 6 and lower were still on Groovy 3.0.x.

Precise simplified example of the code which results in the exception with Groovy 4.0.x compiler: grails/grails-data-mapping#1811 (comment)

grails/grails-data-mapping#1811 (comment) - the decompiled Grails Domain Classes, compiled with Groovy 4.0.23, after changing the exception to a warning. These Grails Domains, with inheritance, compile and run without issue once the exception is removed during pre-compilation verification.

In each instance the Trait or Interface which is implemented with 2+ generic types via inheritance, have generic types which are compatible and extend in a lineage hierarchy.

The Groovy 4 compiler only copies the lowest level Trait or Interface methods into the class, before compiling, which was the approach in Groovy 3 and same and expected approach in Groovy 4.

Example output after restoring Domain Inheritance and Inheritance tests on https://github.com/grails/grails-data-mapping/

> Task :grails-datastore-gorm-tck:compileGroovy
Warning:  on grails.gorm.tests.City the interface GormEntity was implemented more than once with different arguments: org.grails.datastore.gorm.GormEntity<grails.gorm.tests.City> and org.grails.datastore.gorm.GormEntity<grails.gorm.tests.Location>,  grails.gorm.tests.City will only implement the lowest level GormEntity
Warning:  on grails.gorm.tests.City the interface GormEntityApi was implemented more than once with different arguments: org.grails.datastore.gorm.GormEntityApi<grails.gorm.tests.City> and org.grails.datastore.gorm.GormEntityApi<grails.gorm.tests.Location>,  grails.gorm.tests.City will only implement the lowest level GormEntityApi
Warning:  on grails.gorm.tests.City the interface Entity was implemented more than once with different arguments: grails.gorm.Entity<grails.gorm.tests.City> and grails.gorm.Entity<grails.gorm.tests.Location>,  grails.gorm.tests.City will only implement the lowest level Entity
Warning:  on grails.gorm.tests.Country the interface GormEntity was implemented more than once with different arguments: org.grails.datastore.gorm.GormEntity<grails.gorm.tests.Country> and org.grails.datastore.gorm.GormEntity<grails.gorm.tests.Location>,  grails.gorm.tests.Country will only implement the lowest level GormEntity
Warning:  on grails.gorm.tests.Country the interface GormEntityApi was implemented more than once with different arguments: org.grails.datastore.gorm.GormEntityApi<grails.gorm.tests.Country> and org.grails.datastore.gorm.GormEntityApi<grails.gorm.tests.Location>,  grails.gorm.tests.Country will only implement the lowest level GormEntityApi
Warning:  on grails.gorm.tests.Country the interface Entity was implemented more than once with different arguments: grails.gorm.Entity<grails.gorm.tests.Country> and grails.gorm.Entity<grails.gorm.tests.Location>,  grails.gorm.tests.Country will only implement the lowest level Entity

@eric-milles
Copy link
Member

eric-milles commented Oct 25, 2024

I relaxed from an error to a warning for traits: 9d0d671

@eric-milles
Copy link
Member

This should stop the errors for Entity and GormEntity. However, you may still get an error for the interface GormEntityApi per your example. You can try out the snapshot build and let me know: https://groovy.apache.org/snapshots.html

@jamesfredley
Copy link
Author

@eric-milles Thank you for the quick turnaround. We converted GormEntityApi to a Trait and are able to move forward.

grails/grails-data-mapping#1834

@jamesfredley jamesfredley deleted the same-interface-different-type-argument branch October 25, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants