gwtproject / gwt

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

GWT compilation error - Bound mismatch: The type N is not a valid substitute for the bounded parameter #9488

Open zhy2002 opened 7 years ago

zhy2002 commented 7 years ago

GWT version: 2.8 Browser (with version): N/A Operating System: Windows 8


Description

Dagger2 generated MembersInjector compiles fine in Java but fails in GWT 2.8 with the error below:

[ERROR] Errors in 'file:/C:/zhy/code/neutron/examples/target/generated-sources/annotations/zhy2002/neutron/ListUiNode_MembersInjector.java' [INFO] [ERROR] Line 21: Bound mismatch: The type N is not a valid substitute for the bounded parameter <N extends UiNode<? extends ListUiNode<P,N>>> of the type ListUiNode<P,N> [INFO] [ERROR] Aborting compile due to errors in some input files

import dagger.MembersInjector;
import javax.annotation.Generated;
import javax.inject.Provider;

@Generated(
  value = "dagger.internal.codegen.ComponentProcessor",
  comments = "https://google.github.io/dagger"
)
public final class ListUiNode_MembersInjector<
        P extends ObjectUiNode<?>, N extends UiNode<? extends ListUiNode<P, N>>>
    implements MembersInjector<ListUiNode<P, N>> {
  private final Provider<UiNodeRuleProvider> ruleProvider;

  public ListUiNode_MembersInjector(Provider<UiNodeRuleProvider> ruleProvider) {
    assert ruleProvider != null;
    this.ruleProvider = ruleProvider;
  }

  public static <P extends ObjectUiNode<?>, N extends UiNode<? extends ListUiNode<P, N>>>
      MembersInjector<ListUiNode<P, N>> create(Provider<UiNodeRuleProvider> ruleProvider) {
    return new ListUiNode_MembersInjector<P, N>(ruleProvider);
  }

  @Override
  public void injectMembers(ListUiNode<P, N> instance) {
    if (instance == null) {
      throw new NullPointerException("Cannot inject members into a null reference");
    }
    ((UiNode) instance).ruleProvider = ruleProvider.get();
  }
}
public abstract class ListUiNode<P extends ObjectUiNode<?>, N extends UiNode<? extends ListUiNode<P, N>>>
        extends ParentUiNode<P> {
...
}
Steps to reproduce

this is a compilation error

Known workarounds

Change ListUiNode signature to:

public abstract class ListUiNode<P extends ObjectUiNode<?>, N extends UiNode<?>
        extends ParentUiNode<P> {
...
}
Links to further discussions

Also logged an issue with Dagger2 project: https://github.com/google/dagger/issues/586

From my experience the GWT compiler has a number of limitations when handling generics code/Java8 features. Are these documented anywhere so we can avoid these situations?

rluble commented 7 years ago

The error is reported by JDT (the Java "compiler" toolkit part of Eclipse) which GWT uses type check Java. JDT has some open bugs (like https://bugs.eclipse.org/bugs/show_bug.cgi?id=422503) around Java 8 type checking.

zhy2002 commented 7 years ago

Thanks @rluble

jnehlmeier commented 7 years ago

I think we should keep that open as a reminder to update JDT in the future