murat8505 / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 1 forks source link

Lombok "val" inference works when compiled by Eclipse but fails when compiled by Gradle #762

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have a Data Access Object written using jOOQ and it returns a rather complex 
type signature:

Map<Record, Result<Record14<String, Integer, String, String, String, String, 
String, String, Integer, String, Boolean, Boolean, Integer, Boolean>>> result = 
create....
I tried to replace with with Lombok's "val"

val result = create....
This works when I run/compile from Eclipse... When I try to compile within 
Gradle, I get:

    UpdatesDAO.java:307: error: incompatible types
                .fetchGroups(key);
                        ^
      required: val
      found: Map<Record,Result<Record14<String,Integer,String,String,String,String,String,String,Integer,String,Boolean,Boolean,Integer,Boolean>>>

Can anyone tell me why it would work in Gradle for simpler types, but not for 
more complex types? I have other places in this same project which look 
something like:

    val records = dao.getDatastoreById(id); // Returns a type of List<Datastore>

and they work just fine, even when compiled with Gradle... Am I missing 
something?

FYI: Lombok version = 1.14.8, Gradle version 2.2.1, Ubuntu 14.10

I have tried lombok==1.14.6, Gradle version 2.2.0

I have also tried with both Java 8 and Java 7, both OpenJDK and Oracle JDK

Original issue reported on code.google.com by deven.phillips on 19 Dec 2014 at 11:43

GoogleCodeExporter commented 9 years ago
Add enough complexity and 'val' sometimes fails in javac. I thought we recently 
fixed this, but those fixed were in 1.14.8.

Without a self-contained source file that reproduces this problem I don't think 
we can feasibly pick this up right now.

Original comment by reini...@gmail.com on 29 Jan 2015 at 12:34

GoogleCodeExporter commented 9 years ago
I will try to put together an example project today and post a link here.

Original comment by deven.phillips on 29 Jan 2015 at 2:38

GoogleCodeExporter commented 9 years ago
OK, I think I have found the root of the problem and it seems to be very simple 
now that I look at it...

jOOQ has a "DSL" class with a bunch of static methods. The idiomatic way to use 
these methods is to statically import them.. The problem is that there is a 
method in there called "val". When that method is statically imported, the 
lombok "val" stops working. Example code can be found at:

https://github.com/InfoSec812/LombokFailureExample

To compile and run simply execute:

./gradlew run

In the repository root directory.

The version on github currently works, but if you statically import the members 
of the "DSL" class and change the references of "DSL.val()" to just "val()", it 
will fail to compile.

Original comment by deven.phillips on 29 Jan 2015 at 3:20

GoogleCodeExporter commented 9 years ago
How did you statically import val? With 'import static blahblah.val;' or with 
'import static blahblah;'?

Original comment by reini...@gmail.com on 31 Jan 2015 at 3:59

GoogleCodeExporter commented 9 years ago
With:

import static org.jooq.impl.DSL.*;

And 'val' is a static method on the DSL class.

Deven Phillips
from my mobile

Original comment by deven.phillips on 31 Jan 2015 at 12:33

GoogleCodeExporter commented 9 years ago
I assume this will fail with javac too, which means the first step is to 
reproduce this, but it sounds like something we can fix. Accepted.

Original comment by reini...@gmail.com on 8 Feb 2015 at 8:57

GoogleCodeExporter commented 9 years ago
The GitHub project linked above will reproduce the error reliably.

Original comment by deven.phillips on 8 Feb 2015 at 9:16