gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.51k stars 372 forks source link

Extending Interfaces with Generics #8792

Open dankurka opened 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 8831

Found in GWT 2.6.1

What GWT can compile successfully

public interface XYPoint {
Double getX();
Double getY();
}

Public interface XYZPoint extends XYPoint {
Double getZ();
}

public class XYPointJSO extends JavaScriptObject implements XYPoint {
//XYPointJSO implementation
}

public class XYZPointJSO extends XYPointJSO implements XYZPoint {
// XYZPointJSO implementation
}

GWT happily understands that XYPointJSO is the single implementation of XYPoint. However,
if we use Generics for the interfaces such as:

public interface XYPoint<T> {
T getX();
T getY();
}

Public interface XYZPoint<T> extends XYPoint<T> {
T getZ();
}

public class XYPointJSO extends JavaScriptObject implements XYPoint<Double> {
//XYPointJSO implementation
}

public class XYZPointJSO extends XYPointJSO implements XYZPoint<Double> {
// XYZPointJSO implementation
}

GWT does not seem to be able to understand the Java erasure well enough to understand
that XYPointJSO is the single JSO implementation of XYPoint<Double>. When it encounters
XYZPoint<Double> it believes there it has encountered a second XYPoint<Double> JSO
implementation and errors out stating com.google.gwt.dev.jjs.InternalCompilerException:
Already seen an implementing JSO subtype (XYPointJSO) for interface (XYPoint) while
examining newly-added type (XYZPointJSO). This is a bug in JSORestrictionsChecker.

Reported by jpappalardo on 2014-07-21 18:38:50

dankurka commented 9 years ago
The above example doesnt properly demonstrate the error I am encountering, let me try
again

public interface VSD {

}

public interface C {

}

public interface VS<A extends VSD> {

}

public interface VSG<A extends VSD, B extends C> extends VS<A> {

}

public interface VSL<A extends VSD, B extends C, C extends VSS> extends VSG<A, B> {

}

public interface VSA<A extends VSD, B extends C, C extends VSS> extends VSG<A, B> {

}

public interface VSR<A extends VSD> extends VS<A> {

}

public class VSDJso extends JavaScriptObject implements VSD {

}

public class CJso extends JavaScriptObject implements C {

}

public class VSSJso extends JavaScriptObject implements VSS {

}

public class VSJso extends JavaScriptObject implements VS<VSDJso> {

}

public class VSGJso extends VSJso implements VSG<VSDJso, CJso> {

}

public class VSL extends VSGJso implements VSL<VSDJso, CJso, VSSJso> {

}

public class VSA extends VSGJso implements VSA<VSDJso, CJso, VSSJso> {

}

public class VSR extends VSJso implements VSR<VSDJso> {

}

will fail on VSR stating that it has run into two implementations VS. If I make the
following changes:

public interface VSR<A extends VSD, B extends C> extends VSG<A, B> {

}

public class VSRJso extends VSGJso implements VSR<VSDJso, CJso> {

}

then gwt will happily compile.

Reported by jpappalardo on 2014-07-22 20:13:41