Bug 540632 - Generics regression in 4.9 with enums
Summary: Generics regression in 4.9 with enums
Status: CLOSED DUPLICATE of bug 539329
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.9   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.10 M3   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2018-10-30 15:05 EDT by Gunnar Wagenknecht CLA
Modified: 2019-02-05 17:28 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gunnar Wagenknecht CLA 2018-10-30 15:05:42 EDT
Version: 2018-09 (4.9)
Build id: I20180906-0745


Test code:
--------
package test;

import java.util.Map;

public class Test {
    
    public interface MyInterface {}  
    
    public enum ClassA implements MyInterface {}
    public enum ClassB implements MyInterface {}
    public enum ClassC implements MyInterface {}
    public enum ClassD implements MyInterface {}
    
    static Map<String, Class<? extends MyInterface>> ENUM_FIELDS = of(
            "a", ClassA.class,
            "b", ClassB.class,
            "c", ClassC.class,
            "d", ClassD.class);

    
    public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
      return null;
    }
}
--------


Compile error:
The method of(K, V, K, V, K, V, K, V) in the type Test is not applicable for the arguments (String, Class<Test.ClassA>, String, Class<Test.ClassB>, String, Class<Test.ClassC>, String, Class<Test.ClassD>)

If I change the "enum" to "class" the compile error goes away.
Also, switching back to Eclipse 4.7.3 does not result in this error.
Comment 1 Gunnar Wagenknecht CLA 2018-10-30 15:10:51 EDT
Also happens in:

Eclipse IDE for Eclipse Committers

Version: 2018-09 (4.9.0)
Build id: 20180917-1800
Comment 2 Stephan Herrmann CLA 2018-10-30 15:42:13 EDT
Thanks, this used to be accepted by ecj all versions prior to 4.9M2.

More precisely: it's broken since the fix for bug 537089.

Inference seems to fail to infer V to a common super type of Class<ClassA>, Class<ClassB> ... I guess previously, we "accidentally" inferred a wildcard, need to check if that is legal and can be restored for this situation.
Comment 3 Gunnar Wagenknecht CLA 2018-11-01 09:04:45 EDT
Stephan, a college (who discovered this originally) also discovered that this depends on the number of arguments of the "of" method. Two seems to work fine.


----
package test;
 
import java.util.Map;
 
public class Test {
    
    public interface MyInterface {}  
    
    public enum ClassA implements MyInterface {}
    public enum ClassB implements MyInterface {}
    public enum ClassC implements MyInterface {}
    
    static Map<String, Class<? extends MyInterface>> ENUM_FIELDS_WORKING = of(
            "a", ClassA.class,
            "b", ClassB.class);
    
    static Map<String, Class<? extends MyInterface>> ENUM_FIELDS_FAILURE = of(
            "a", ClassA.class,
            "b", ClassB.class,
            "c", ClassC.class);
 
    
    public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2) {
      return null;
    }
    
    public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) {
        return null;
      }
 
}
----
Comment 4 Stephan Herrmann CLA 2018-11-01 09:26:08 EDT
(In reply to Gunnar Wagenknecht from comment #3)
> Stephan, a college (who discovered this originally) also discovered that
> this depends on the number of arguments of the "of" method. Two seems to
> work fine.

Thanks. This is plausible, intersections types become more challenging when more than 2 constituents are involved.
Comment 5 Stephan Herrmann CLA 2019-02-05 17:28:17 EST
Works again since 4.10.

*** This bug has been marked as a duplicate of bug 539329 ***