6946618: sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms.

Wed, 19 May 2010 16:42:37 +0100

author
mcimadamore
date
Wed, 19 May 2010 16:42:37 +0100
changeset 562
2881b376a689
parent 561
e9ef849ae0ed
child 563
eb849389ae2c

6946618: sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms.
Summary: Bad cast to ClassType in the new diamond implementation fails if the target type of the instance creation expression is a type-variable
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6946618/T6946618a.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6946618/T6946618a.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/6946618/T6946618b.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6946618/T6946618b.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/6946618/T6946618c.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6946618/T6946618c.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed May 19 16:41:57 2010 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed May 19 16:42:37 2010 +0100
     1.3 @@ -1472,7 +1472,7 @@
     1.4          // Attribute clazz expression and store
     1.5          // symbol + type back into the attributed tree.
     1.6          Type clazztype = attribType(clazz, env);
     1.7 -        Pair<Scope,Scope> mapping = getSyntheticScopeMapping((ClassType)clazztype);
     1.8 +        Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype);
     1.9          if (!TreeInfo.isDiamond(tree)) {
    1.10              clazztype = chk.checkClassType(
    1.11                  tree.clazz.pos(), clazztype, true);
    1.12 @@ -1640,9 +1640,10 @@
    1.13                          List<Type> argtypes,
    1.14                          List<Type> typeargtypes,
    1.15                          boolean reportErrors) {
    1.16 -        if (clazztype.isErroneous()) {
    1.17 -            //if the type of the instance creation expression is erroneous
    1.18 -            //return the erroneous type itself
    1.19 +        if (clazztype.isErroneous() || mapping == erroneousMapping) {
    1.20 +            //if the type of the instance creation expression is erroneous,
    1.21 +            //or something prevented us to form a valid mapping, return the
    1.22 +            //(possibly erroneous) type unchanged
    1.23              return clazztype;
    1.24          }
    1.25          else if (clazztype.isInterface()) {
    1.26 @@ -1740,7 +1741,10 @@
    1.27       *  inference. The inferred return type of the synthetic constructor IS
    1.28       *  the inferred type for the diamond operator.
    1.29       */
    1.30 -    private Pair<Scope, Scope> getSyntheticScopeMapping(ClassType ctype) {
    1.31 +    private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
    1.32 +        if (ctype.tag != CLASS) {
    1.33 +            return erroneousMapping;
    1.34 +        }
    1.35          Pair<Scope, Scope> mapping =
    1.36                  new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
    1.37          List<Type> typevars = ctype.tsym.type.getTypeArguments();
    1.38 @@ -1763,6 +1767,8 @@
    1.39          return mapping;
    1.40      }
    1.41  
    1.42 +    private final Pair<Scope,Scope> erroneousMapping = new Pair<Scope,Scope>(null, null);
    1.43 +
    1.44      /** Make an attributed null check tree.
    1.45       */
    1.46      public JCExpression makeNullCheck(JCExpression arg) {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/6946618/T6946618a.java	Wed May 19 16:42:37 2010 +0100
     2.3 @@ -0,0 +1,21 @@
     2.4 +/*
     2.5 + * @test /nodynamiccopyright/
     2.6 + * @bug     6946618
     2.7 + * @summary sqe test fails: javac/generics/NewOnTypeParm  in pit jdk7 b91 in all platforms.
     2.8 + * @author  mcimadamore
     2.9 + * @compile/fail/ref=T6946618a.out -XDrawDiagnostics T6946618a.java
    2.10 + */
    2.11 +
    2.12 +class T6946618a {
    2.13 +    static class C<T> {
    2.14 +      T makeT() {
    2.15 +        return new T(); //error
    2.16 +      }
    2.17 +    }
    2.18 +
    2.19 +    static class D<S> {
    2.20 +      C<S> makeC() {
    2.21 +        return new C<S>(); //ok
    2.22 +      }
    2.23 +    }
    2.24 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/generics/6946618/T6946618a.out	Wed May 19 16:42:37 2010 +0100
     3.3 @@ -0,0 +1,2 @@
     3.4 +T6946618a.java:12:20: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class)
     3.5 +1 error
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/generics/6946618/T6946618b.java	Wed May 19 16:42:37 2010 +0100
     4.3 @@ -0,0 +1,21 @@
     4.4 +/*
     4.5 + * @test /nodynamiccopyright/
     4.6 + * @bug     6946618
     4.7 + * @summary sqe test fails: javac/generics/NewOnTypeParm  in pit jdk7 b91 in all platforms.
     4.8 + * @author  mcimadamore
     4.9 + * @compile/fail/ref=T6946618b.out -XDrawDiagnostics T6946618b.java
    4.10 + */
    4.11 +
    4.12 +class T6946618b {
    4.13 +    static class C<T> {
    4.14 +      T makeT() {
    4.15 +        return new T<>(); //error
    4.16 +      }
    4.17 +    }
    4.18 +
    4.19 +    static class D<S> {
    4.20 +      C<S> makeC() {
    4.21 +        return new C<>(); //ok
    4.22 +      }
    4.23 +    }
    4.24 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/generics/6946618/T6946618b.out	Wed May 19 16:42:37 2010 +0100
     5.3 @@ -0,0 +1,2 @@
     5.4 +T6946618b.java:12:20: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class)
     5.5 +1 error
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/generics/6946618/T6946618c.java	Wed May 19 16:42:37 2010 +0100
     6.3 @@ -0,0 +1,17 @@
     6.4 +/*
     6.5 + * @test /nodynamiccopyright/
     6.6 + * @bug     6946618
     6.7 + * @summary sqe test fails: javac/generics/NewOnTypeParm  in pit jdk7 b91 in all platforms.
     6.8 + * @author  mcimadamore
     6.9 + * @compile/fail/ref=T6946618c.out -XDrawDiagnostics T6946618c.java
    6.10 + */
    6.11 +
    6.12 +class T6946618c {
    6.13 +    static class C<T> { }
    6.14 +
    6.15 +    void test() {
    6.16 +        C<?> c1 = new C<? extends String>();
    6.17 +        C<?> c2 = new C<? super String>();
    6.18 +        C<?> c3 = new C<?>();
    6.19 +    }
    6.20 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javac/generics/6946618/T6946618c.out	Wed May 19 16:42:37 2010 +0100
     7.3 @@ -0,0 +1,4 @@
     7.4 +T6946618c.java:13:24: compiler.err.type.found.req: ? extends java.lang.String, class or interface without bounds
     7.5 +T6946618c.java:14:24: compiler.err.type.found.req: ? super java.lang.String, class or interface without bounds
     7.6 +T6946618c.java:15:24: compiler.err.type.found.req: ?, class or interface without bounds
     7.7 +3 errors

mercurial