Inference variable has incompatible bounds. Java 8 Compiler Regression?

后端 未结 3 509
一个人的身影
一个人的身影 2020-12-31 00:56

The following program compiles in Java 7 and in Eclipse Mars RC2 for Java 8:

import java.util.List;

public class Test {

    static final void a(Class

        
3条回答
  •  轮回少年
    2020-12-31 01:34

    Thanks for the bug report, and thanks, Holger, for the example in your answer. These and several others finally made me question one small change made in the Eclipse compiler 11 years ago. The point was: Eclipse had illegally extended the capture algorithm to apply recursively to wildcard bounds.

    There was one example where this illegal change perfectly aligned Eclipse behavior with javac. Generations of Eclipse developers have trusted this old decision more than what we could clearly see in JLS. Today I believe that previous deviation must have had a different reason.

    Today I took the courage to align ecj with JLS in this regard and voila 5 bugs that appeared to be extremely hard to crack, have essentially been solved just like that (plus a little tweak here and there as compensation).

    Ergo: Yes, Eclipse had a bug, but that bug has been fixed as of 4.7 milestone 2 :)

    Here's what ecj will report henceforth:

    The method b(List) in the type Test is not applicable for the arguments (capture#1-of ? extends List)
    

    It's the wildcard inside a capture bound that doesn't find a rule to detect compatibility. More precisely, some time during inference (incorporation to be precise) we encounter the following constraint (T#0 representing an inference variable):

    ⟨T#0 = ?⟩
    

    Naively, we could just resolve the type variable to the wildcard, but -- presumably because wildcards are not considered types -- the reduction rules define the above as reducing to FALSE, thus letting inference fail.

提交回复
热议问题