6400189: raw types and inference

Wed, 25 Mar 2009 10:29:28 +0000

author
mcimadamore
date
Wed, 25 Mar 2009 10:29:28 +0000
changeset 254
1ee128971f5d
parent 253
6ce39250fa88
child 255
07da2ffbb76b

6400189: raw types and inference
Summary: Fixed resolution problem with raw overriding (CCC)
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
test/tools/javac/OverrideChecks/6400189/T6400189a.java file | annotate | diff | comparison | revisions
test/tools/javac/OverrideChecks/6400189/T6400189a.out file | annotate | diff | comparison | revisions
test/tools/javac/OverrideChecks/6400189/T6400189b.java file | annotate | diff | comparison | revisions
test/tools/javac/OverrideChecks/6400189/T6400189b.out file | annotate | diff | comparison | revisions
test/tools/javac/OverrideChecks/6400189/T6400189c.java file | annotate | diff | comparison | revisions
test/tools/javac/OverrideChecks/6400189/T6400189d.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Mar 25 10:28:52 2009 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Mar 25 10:29:28 2009 +0000
     1.3 @@ -216,7 +216,9 @@
     1.4                  &&
     1.5                  isAccessible(env, site)
     1.6                  &&
     1.7 -                sym.isInheritedIn(site.tsym, types);
     1.8 +                sym.isInheritedIn(site.tsym, types)
     1.9 +                &&
    1.10 +                notOverriddenIn(site, sym);
    1.11          case PROTECTED:
    1.12              return
    1.13                  (env.toplevel.packge == sym.owner.owner // fast special case
    1.14 @@ -231,14 +233,23 @@
    1.15                  &&
    1.16                  isAccessible(env, site)
    1.17                  &&
    1.18 -                // `sym' is accessible only if not overridden by
    1.19 -                // another symbol which is a member of `site'
    1.20 -                // (because, if it is overridden, `sym' is not strictly
    1.21 -                // speaking a member of `site'.)
    1.22 -                (sym.kind != MTH || sym.isConstructor() || sym.isStatic() ||
    1.23 -                 ((MethodSymbol)sym).implementation(site.tsym, types, true) == sym);
    1.24 +                notOverriddenIn(site, sym);
    1.25          default: // this case includes erroneous combinations as well
    1.26 -            return isAccessible(env, site);
    1.27 +            return isAccessible(env, site) && notOverriddenIn(site, sym);
    1.28 +        }
    1.29 +    }
    1.30 +    //where
    1.31 +    /* `sym' is accessible only if not overridden by
    1.32 +     * another symbol which is a member of `site'
    1.33 +     * (because, if it is overridden, `sym' is not strictly
    1.34 +     * speaking a member of `site'.)
    1.35 +     */
    1.36 +    private boolean notOverriddenIn(Type site, Symbol sym) {
    1.37 +        if (sym.kind != MTH || sym.isConstructor() || sym.isStatic())
    1.38 +            return true;
    1.39 +        else {
    1.40 +            Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true);
    1.41 +            return (s2 == null || s2 == sym);
    1.42          }
    1.43      }
    1.44      //where
    1.45 @@ -605,7 +616,7 @@
    1.46      Symbol mostSpecific(Symbol m1,
    1.47                          Symbol m2,
    1.48                          Env<AttrContext> env,
    1.49 -                        Type site,
    1.50 +                        final Type site,
    1.51                          boolean allowBoxing,
    1.52                          boolean useVarargs) {
    1.53          switch (m2.kind) {
    1.54 @@ -661,21 +672,33 @@
    1.55                                         m2.erasure(types).getParameterTypes()))
    1.56                      return new AmbiguityError(m1, m2);
    1.57                  // both abstract, neither overridden; merge throws clause and result type
    1.58 -                Symbol result;
    1.59 +                Symbol mostSpecific;
    1.60                  Type result2 = mt2.getReturnType();
    1.61                  if (mt2.tag == FORALL)
    1.62                      result2 = types.subst(result2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars);
    1.63                  if (types.isSubtype(mt1.getReturnType(), result2)) {
    1.64 -                    result = m1;
    1.65 +                    mostSpecific = m1;
    1.66                  } else if (types.isSubtype(result2, mt1.getReturnType())) {
    1.67 -                    result = m2;
    1.68 +                    mostSpecific = m2;
    1.69                  } else {
    1.70                      // Theoretically, this can't happen, but it is possible
    1.71                      // due to error recovery or mixing incompatible class files
    1.72                      return new AmbiguityError(m1, m2);
    1.73                  }
    1.74 -                result = result.clone(result.owner);
    1.75 -                result.type = (Type)result.type.clone();
    1.76 +                MethodSymbol result = new MethodSymbol(
    1.77 +                        mostSpecific.flags(),
    1.78 +                        mostSpecific.name,
    1.79 +                        null,
    1.80 +                        mostSpecific.owner) {
    1.81 +                    @Override
    1.82 +                    public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
    1.83 +                        if (origin == site.tsym)
    1.84 +                            return this;
    1.85 +                        else
    1.86 +                            return super.implementation(origin, types, checkResult);
    1.87 +                    }
    1.88 +                };
    1.89 +                result.type = (Type)mostSpecific.type.clone();
    1.90                  result.type.setThrown(chk.intersect(mt1.getThrownTypes(),
    1.91                                                      mt2.getThrownTypes()));
    1.92                  return result;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/OverrideChecks/6400189/T6400189a.java	Wed Mar 25 10:29:28 2009 +0000
     2.3 @@ -0,0 +1,38 @@
     2.4 +/*
     2.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug     6400189
    2.30 + * @summary raw types and inference
    2.31 + * @author  mcimadamore
    2.32 + * @compile/fail/ref=T6400189a.out T6400189a.java -Xlint:unchecked -XDrawDiagnostics
    2.33 + */
    2.34 +
    2.35 +import java.lang.reflect.Constructor;
    2.36 +import java.lang.annotation.Documented;
    2.37 +
    2.38 +class T6400189a {
    2.39 +    Constructor c = null;
    2.40 +    Documented d = c.getAnnotation(Documented.class);
    2.41 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/OverrideChecks/6400189/T6400189a.out	Wed Mar 25 10:29:28 2009 +0000
     3.3 @@ -0,0 +1,4 @@
     3.4 +T6400189a.java:37:35: compiler.warn.unchecked.call.mbr.of.raw.type: <T>getAnnotation(java.lang.Class<T>), java.lang.reflect.Constructor
     3.5 +T6400189a.java:37:35: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.annotation.Annotation, java.lang.annotation.Documented
     3.6 +1 error
     3.7 +1 warning
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/OverrideChecks/6400189/T6400189b.java	Wed Mar 25 10:29:28 2009 +0000
     4.3 @@ -0,0 +1,49 @@
     4.4 +/*
     4.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    4.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    4.24 + * have any questions.
    4.25 + */
    4.26 +
    4.27 +/*
    4.28 + * @test
    4.29 + * @bug     6400189
    4.30 + * @summary raw types and inference
    4.31 + * @author  mcimadamore
    4.32 + * @compile/fail/ref=T6400189b.out T6400189b.java -Xlint:unchecked -XDrawDiagnostics
    4.33 + */
    4.34 +
    4.35 +class T6400189b<T> {
    4.36 +
    4.37 +    static class A {
    4.38 +        <T> T m(T6400189b<T> x) {
    4.39 +            return null;
    4.40 +        }
    4.41 +    }
    4.42 +
    4.43 +    static class B<T> extends A {
    4.44 +        <T> T m(T6400189b<T> x) {
    4.45 +            return null;
    4.46 +        }
    4.47 +    }
    4.48 +
    4.49 +    void test(B b) {
    4.50 +        Integer i = b.m(new T6400189b<Integer>());
    4.51 +    }
    4.52 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/OverrideChecks/6400189/T6400189b.out	Wed Mar 25 10:29:28 2009 +0000
     5.3 @@ -0,0 +1,4 @@
     5.4 +T6400189b.java:47:24: compiler.warn.unchecked.call.mbr.of.raw.type: <T>m(T6400189b<T>), T6400189b.B
     5.5 +T6400189b.java:47:24: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Object, java.lang.Integer
     5.6 +1 error
     5.7 +1 warning
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/OverrideChecks/6400189/T6400189c.java	Wed Mar 25 10:29:28 2009 +0000
     6.3 @@ -0,0 +1,45 @@
     6.4 +/*
     6.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    6.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    6.24 + * have any questions.
    6.25 + */
    6.26 +
    6.27 +/*
    6.28 + * @test
    6.29 + * @bug     6400189
    6.30 + * @summary raw types and inference
    6.31 + * @author  mcimadamore
    6.32 + * @compile T6400189c.java
    6.33 + */
    6.34 +
    6.35 +class T6400189c<T> {
    6.36 +
    6.37 +    static class A {
    6.38 +        <T> T m(T6400189c<T> x) {
    6.39 +            return null;
    6.40 +        }
    6.41 +    }
    6.42 +
    6.43 +    static class B<T> extends A {}
    6.44 +
    6.45 +    void test(B b) {
    6.46 +        Integer i = b.m(new T6400189c<Integer>());
    6.47 +    }
    6.48 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javac/OverrideChecks/6400189/T6400189d.java	Wed Mar 25 10:29:28 2009 +0000
     7.3 @@ -0,0 +1,53 @@
     7.4 +/*
     7.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.
    7.11 + *
    7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 + * version 2 for more details (a copy is included in the LICENSE file that
    7.16 + * accompanied this code).
    7.17 + *
    7.18 + * You should have received a copy of the GNU General Public License version
    7.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 + *
    7.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    7.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    7.24 + * have any questions.
    7.25 + */
    7.26 +
    7.27 +/*
    7.28 + * @test
    7.29 + * @bug     6400189
    7.30 + * @summary raw types and inference
    7.31 + * @author  mcimadamore
    7.32 + * @compile T6400189d.java
    7.33 + */
    7.34 +
    7.35 +import java.util.Iterator;
    7.36 +
    7.37 +class T6400189c<T> {
    7.38 +
    7.39 +    interface A<X> extends Iterable<X> {
    7.40 +        Iterator<X> iterator();
    7.41 +    }
    7.42 +
    7.43 +    interface A2<Y> extends A<Y> {
    7.44 +        Iterator<Y> iterator();
    7.45 +    }
    7.46 +
    7.47 +    static abstract class B<Z> implements A<Z> {
    7.48 +        public abstract Iterator<Z> iterator();
    7.49 +    }
    7.50 +
    7.51 +    static abstract class C<W> extends B<W> implements A2<W> {
    7.52 +        Iterator<W> test() {
    7.53 +            return iterator();
    7.54 +        }
    7.55 +    }
    7.56 +}

mercurial