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

@Trait applied to interface with generic cause compile error #733

Closed
AntonPanikov opened this issue Sep 25, 2018 · 24 comments
Closed

@Trait applied to interface with generic cause compile error #733

AntonPanikov opened this issue Sep 25, 2018 · 24 comments
Assignees
Labels
Milestone

Comments

@AntonPanikov
Copy link

I found one more bug related to Grails projects, but I do not think it is Grails related, but @trait annotation related. I was unable to extract and isolate this issue in the pure groovy project.

I am using:
Eclipse Oxygen.3a Release (4.7.3a)
Groovy-Eclipse 3.1.0.xx-201809251603-e47

It is easy to reproduce with SDKMAN:

Install sdkman:
curl -s "https://get.sdkman.io" | bash
Source or open new shell:
source "$HOME/.sdkman/bin/sdkman-init.sh"
Install grails:
sdk i grails
Create sample app in some folder (grails-example):
grails create-app --profile web --inplace
Create sample service:
grails create-service sample

Import this project into eclipse and add Gradle nature. Edit grails-sample/grails-app/services/grails/sample/SampleService.groovy, like this:

package grails.sample

import grails.events.Events
import grails.gorm.transactions.Transactional

@Transactional
class SampleService implements Events {
}

Copy this service as SampleService2 and just add reference to the previous one:

package grails.sample

import grails.gorm.transactions.Transactional

@Transactional
class SampleService2 {
    SampleService sampleService
}

The second one will start complain about:

Inconsistent classfile encountered: The undefined type parameter T is referenced from within SampleService

I believe it is T generic from Event interface, but I can not reproduce it in pure groovy.

Same complain from generated UnitTest class. Sometime this error is gone, but as soon as I clean or edit the source, just adding and removing space character for example, it will come back.

I am attaching my sample app zip here, just in case.
grails-sample.zip

@eric-milles
Copy link
Member

I'm not seeing any error. In the sample project supplied, grails.events.Events resolves to a deprecated trait that does not have any type parameters. Most methods do have generic types, but you aren't referencing any of those yet.

@AntonPanikov
Copy link
Author

This is from grails 3.2 where events is not deprecated, but I have compile error on 3.3 project that I attached. As I said it is tricky and sometimes error not show up until you edit file. Just try to edit SampleService2, just add new empty line and save. It will show up.

I believe it is refer to T type from grails.events.Events:

<T> Event<T> eventFor(T var1);

compile_error1
compile_error2

@eric-milles
Copy link
Member

Got it. So this only happens on incremental build. If you need to get unstuck, you can clean and rebuild all.

When SampleService2 is trying to resolve the reference to SampleService, it encounters this error when lazily resolving methods. In this case, the method appears to be:

org.eclipse.jdt.internal.compiler.classfmt.MethodInfo{public grails_events_Eventstrait$super$sendAndReceive<E:Lreactor/bus/Event<*>;>(Ljava/lang/Object;Lgroovy/lang/Closure;)Lreactor/bus/Bus;}

<E:Lreactor/bus/Event<TT; ^ >;>(Ljava/lang/Object;Lgroovy/lang/Closure<TE;>;)Lreactor/bus/Bus;

Unresolved type reactor.bus.Event

This may be a flavor of #548. I'll have more info on that soon.

@eric-milles
Copy link
Member

So the problem lies in the compiled class file that greclipse produces. When incremental compile runs, it uses the class file instead of the source. This is where it is getting the invalid generics from.

On the left side is the Gradle build result (javap dump) and on the right is the Greclipse result:
diff

@eric-milles
Copy link
Member

See GROOVY-8815

@eric-milles
Copy link
Member

Ready to test

@eric-milles eric-milles added this to the v3.1.0 milestone Sep 29, 2018
@eric-milles eric-milles self-assigned this Sep 29, 2018
@AntonPanikov
Copy link
Author

Tried on: 3.1.0.xx-201810010340-e47
I am still having this issue. Once I make any changes in SampleService2 or SampleServiceSpec and save it, after incremental build, it is showing the same error. I am using the same sample project attached above.

@eric-milles
Copy link
Member

Did you clean your workspace and rebuild the project?

@AntonPanikov
Copy link
Author

I tried to Clean/Build all. I even deleted and re-imported project form the zip. Even after that, incremental build casing the error.

@eric-milles
Copy link
Member

eric-milles commented Oct 2, 2018

Is it the exact same error? Does your project build with Gradle or some other compiler?

@AntonPanikov
Copy link
Author

Yes, it is the exactly same error. And yes I can build and run it with gradle.

@eric-milles
Copy link
Member

What version of the Groovy Compiler are you using? This all has to do with the compiler and any compiler besides the Groovy-Eclipse compiler will not have the necessary patch.

@AntonPanikov
Copy link
Author

As I mentioned:
Groovy Compiler 2.4
3.1.0.xx-201810010340-e47

@eric-milles
Copy link
Member

It should look something like this, 3.1.0 will not be on the compiler plug-in.

image

@AntonPanikov
Copy link
Author

groovy_compiler

@eric-milles
Copy link
Member

Could you attach your SampleService.class file?

@AntonPanikov
Copy link
Author

SampleService.class.zip

@eric-milles
Copy link
Member

I see the error. I'm not sure if it is because Events was compiled with generics that the current compiler doesn't produce. That class is pre-compiled in your scenario. I tried to extract the test case from it and so I have a source file in its place.

@eric-milles
Copy link
Member

Ready to test

@AntonPanikov
Copy link
Author

Tested on:
Groovy Compiler 2.4 3.1.0.xx-201810082206-e47
Groovy Runtime 2.4.15.xx-201810082206-e47

It is working now.

@eric-milles
Copy link
Member

Thanks for trying it out. I am testing one final version of a fix for this. Would you mind testing that when the build completes?

@AntonPanikov
Copy link
Author

Yes, sure. Just let me know when it is ready for test again.

eric-milles added a commit that referenced this issue Oct 9, 2018
- refactor of last commit to manage redirect better during conversion
from JDT Model to Groovy AST
@eric-milles
Copy link
Member

Ready to retest

@AntonPanikov
Copy link
Author

Tested on:
Groovy Compiler 2.4: 3.1.0.xx-201810091927-e47
Groovy Runtime: 2.4.15.xx-201810091927-e47

It is working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants