6557182: Unchecked warning *and* inconvertible types

Thu, 29 Jan 2009 12:18:19 +0000

author
mcimadamore
date
Thu, 29 Jan 2009 12:18:19 +0000
changeset 211
4542977c959e
parent 210
1aa81917016a
child 212
79f2f2c7d846

6557182: Unchecked warning *and* inconvertible types
Summary: Redundant warnings are generated when casting from intersection types
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
test/tools/javac/cast/6557182/T6557182.java file | annotate | diff | comparison | revisions
test/tools/javac/cast/6557182/T6557182.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Jan 29 12:17:57 2009 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Jan 29 12:18:19 2009 +0000
     1.3 @@ -949,12 +949,16 @@
     1.4                  }
     1.5  
     1.6                  if (t.isCompound()) {
     1.7 +                    Warner oldWarner = warnStack.head;
     1.8 +                    warnStack.head = Warner.noWarnings;
     1.9                      if (!visit(supertype(t), s))
    1.10                          return false;
    1.11                      for (Type intf : interfaces(t)) {
    1.12                          if (!visit(intf, s))
    1.13                              return false;
    1.14                      }
    1.15 +                    if (warnStack.head.unchecked == true)
    1.16 +                        oldWarner.warnUnchecked();
    1.17                      return true;
    1.18                  }
    1.19  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/cast/6557182/T6557182.java	Thu Jan 29 12:18:19 2009 +0000
     2.3 @@ -0,0 +1,41 @@
     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 + * @author Maurizio Cimadamore
    2.30 + * @bug     6557182
    2.31 + * @summary  Unchecked warning *and* inconvertible types
    2.32 + * @compile/fail/ref=T6557182.out -XDrawDiagnostics -Xlint:unchecked T6557182.java
    2.33 + */
    2.34 +
    2.35 +class T6557182 {
    2.36 +
    2.37 +    <T extends Number & Comparable<String>> void test1(T t) {
    2.38 +        Comparable<Integer> ci = (Comparable<Integer>) t;
    2.39 +    }
    2.40 +
    2.41 +    <T extends Number & Comparable<? extends Number>> void test2(T t) {
    2.42 +        Comparable<Integer> ci = (Comparable<Integer>) t;
    2.43 +    }
    2.44 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/cast/6557182/T6557182.out	Thu Jan 29 12:18:19 2009 +0000
     3.3 @@ -0,0 +1,4 @@
     3.4 +T6557182.java:35:56: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T, java.lang.Comparable<java.lang.Integer>
     3.5 +T6557182.java:39:56: compiler.warn.prob.found.req: (- compiler.misc.unchecked.cast.to.type), T, java.lang.Comparable<java.lang.Integer>
     3.6 +1 error
     3.7 +1 warning

mercurial