Bug 434115 - Compilation error on generic capture/type inference with AJC 1.8.0
Summary: Compilation error on generic capture/type inference with AJC 1.8.0
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.0   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 434118
Blocks:
  Show dependency tree
 
Reported: 2014-05-05 09:17 EDT by Frank Pavageau CLA
Modified: 2014-05-05 12:03 EDT (History)
1 user (show)

See Also:


Attachments
Test case (998 bytes, application/gzip)
2014-05-05 09:17 EDT, Frank Pavageau CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Pavageau CLA 2014-05-05 09:17:37 EDT
Created attachment 242705 [details]
Test case

The attached example fails to compile with AJC 1.8.0 (or a snapshot of 1.8.1) but compiles perfectly with 1.6 or 1.7. It also compiles with javac from JDK 6, 7 or 8.

[ERROR] /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java:3:0::0 The method valueOf(Class<T>, String) in the type Enum is not applicable for the arguments (Class<capture#2-of ? extends Enum>, String)

The example class has 3 methods with minute variations, only the first one fails to compile. If I specify the generic parameter on the method call, or extract the result as a variable, it works.

To be honest, it seems to be a problem with ECJ, as I get the same error when using the most recent snapshot of ECJ deployed to Maven Central:
~/devs/aspectj/wildcard-capture/src/main/java$ java -jar ~/.m2/repository/org/eclipse/jdt/core/compiler/ecj/P20140317-1600/ecj-P20140317-1600.jar -1.8 -deprecation WildcardCapture.java 
----------
1. ERROR in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 3)
	return Enum.valueOf(clazz.asSubclass(Enum.class), value);
	            ^^^^^^^
The method valueOf(Class<T>, String) in the type Enum is not applicable for the arguments (Class<capture#2-of ? extends Enum>, String)
----------
2. WARNING in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 7)
	return Enum.valueOf(clazz.<Enum>asSubclass(Enum.class), value);
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type safety: Unchecked invocation valueOf(Class<capture#4-of ? extends Enum>, String) of the generic method valueOf(Class<T>, String) of type Enum
----------
3. WARNING in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 7)
	return Enum.valueOf(clazz.<Enum>asSubclass(Enum.class), value);
	                           ^^^^
Enum is a raw type. References to generic type Enum<E> should be parameterized
----------
4. WARNING in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 11)
	Class<? extends Enum> enumType = clazz.asSubclass(Enum.class);
	                ^^^^
Enum is a raw type. References to generic type Enum<E> should be parameterized
----------
5. WARNING in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 12)
	return Enum.valueOf(enumType, value);
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type safety: Unchecked invocation valueOf(Class<capture#7-of ? extends Enum>, String) of the generic method valueOf(Class<T>, String) of type Enum
----------
5 problems (1 error, 4 warnings)

ECJ also sees warnings when javac doesn't, by the way.

So I should probably report the problem to ECJ (in JDT/Core, I guess), but this bug is still needed so you know you'll have to upgrade if/when it's fixed.
Comment 1 Andrew Clement CLA 2014-05-05 11:57:01 EDT
Hey. Thanks for the report - are you also going to raise a JDT bug?
Comment 2 Frank Pavageau CLA 2014-05-05 12:03:05 EDT
Yes, I raised a JDT bug and set it as a dependency of this one.