Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inscrutable error possibly due to failure to infer generic types #3568

Closed
msridhar opened this issue Aug 6, 2020 · 1 comment
Closed

Inscrutable error possibly due to failure to infer generic types #3568

msridhar opened this issue Aug 6, 2020 · 1 comment

Comments

@msridhar
Copy link
Contributor

msridhar commented Aug 6, 2020

This is related to #3035 and #3044. We may have missed a case there. This is as small as I could make the repro example (reduced from code in https://github.com/h2oai/h2o-3):

class GenericFailure {
    public interface Freezable<T extends Freezable> extends Cloneable {}
    public static final class Key<T extends Keyed> extends Iced<Key<T>> implements Comparable {
        @Override
        public int compareTo(Object o) {
            return 0;
        }
    }
    public abstract static class Keyed<T extends Keyed> extends Iced<T> {}
    public static final class Job<T extends Keyed> extends Keyed<Job> {
        public Job(Key<T> key, String clz_of_T, String desc) {}
    }
    public abstract static class Lockable<T extends Lockable<T>> extends Keyed<T> {}
    public abstract static class Iced<D extends Iced>
            implements Freezable<D>, java.io.Externalizable {
        @Override
        public void readExternal(java.io.ObjectInput ois)
                throws java.io.IOException, ClassNotFoundException {}
        @Override
        public void writeExternal(java.io.ObjectOutput oos) throws java.io.IOException {}
    }
    public abstract static class Model<
                    M extends Model<M, P, O>, P extends Model.Parameters, O extends Model.Output>
            extends Lockable<M> {
        public abstract static class Parameters extends Iced<Parameters> {
            abstract String algoName();
            abstract String javaName();
        }
        public abstract static class Output extends Iced {}
    }
    public abstract static class ModelBuilder<
                    M extends Model<M, P, O>, P extends Model.Parameters, O extends Model.Output>
            extends Iced {
        public static <B extends ModelBuilder, MP extends Model.Parameters> B make(
                MP parms, Key<Model> mKey) {
            Job<Model> mJob = new Job<>(mKey, parms.javaName(), parms.algoName());
            B newMB = ModelBuilder.make(parms.algoName(), mJob, mKey);
            return newMB;
        }
        public static <B extends ModelBuilder> B make(String algo, Job job, Key<Model> result) {
            return null;
        }
    }
}

When I run with tainting checker I get:

$ ./checker/bin/javac -processor TaintingChecker checker/tests/tainting/GenericFailure.java
checker/tests/tainting/GenericFailure.java:54: error: [return.type.incompatible] incompatible types in return.
            return newMB;
                   ^
  type of expression: B extends @Tainted ModelBuilder</*INFERENCE FAILED for:*/ ? extends @Tainted Model</*INFERENCE FAILED for:*/ ?, /*INFERENCE FAILED for:*/ ? extends @Tainted Parameters, /*INFERENCE FAILED for:*/ ? extends @Tainted Output>, /*INFERENCE FAILED for:*/ ? extends @Tainted Parameters, /*INFERENCE FAILED for:*/ ? extends @Tainted Output>
  method return type: B extends @Tainted ModelBuilder</*INFERENCE FAILED for:*/ ? extends @Tainted Model<M extends @Tainted Model<M extends @Tainted Model<M, P extends @Tainted Parameters, O extends @Tainted Output>, P extends @Tainted Parameters, O extends @Tainted Output>, P extends @Tainted Parameters, O extends @Tainted Output>, /*INFERENCE FAILED for:*/ ? extends @Tainted Parameters, /*INFERENCE FAILED for:*/ ? extends @Tainted Output>
1 error

I think we should not be reporting this error unless -AconservativeUninferredTypeArguments is passed.

@msridhar
Copy link
Contributor Author

I just checked and this passes the checker now! Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant