6804733: javac generates spourious diagnostics for ill-formed type-variable bounds

Thu, 05 Mar 2009 17:24:40 +0000

author
mcimadamore
date
Thu, 05 Mar 2009 17:24:40 +0000
changeset 236
84a18d7da478
parent 235
850869f70213
child 237
9711a6c2db7e

6804733: javac generates spourious diagnostics for ill-formed type-variable bounds
Summary: fixed algorithm for checking cycles in typevar declarations
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/typevars/6804733/T6804733.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/typevars/6804733/T6804733.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Mar 05 17:24:08 2009 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Mar 05 17:24:40 2009 +0000
     1.3 @@ -1545,10 +1545,10 @@
     1.4  
     1.5  
     1.6      void checkNonCyclic(DiagnosticPosition pos, TypeVar t) {
     1.7 -        checkNonCyclic1(pos, t, new HashSet<TypeVar>());
     1.8 +        checkNonCyclic1(pos, t, List.<TypeVar>nil());
     1.9      }
    1.10  
    1.11 -    private void checkNonCyclic1(DiagnosticPosition pos, Type t, Set<TypeVar> seen) {
    1.12 +    private void checkNonCyclic1(DiagnosticPosition pos, Type t, List<TypeVar> seen) {
    1.13          final TypeVar tv;
    1.14          if  (t.tag == TYPEVAR && (t.tsym.flags() & UNATTRIBUTED) != 0)
    1.15              return;
    1.16 @@ -1558,7 +1558,7 @@
    1.17              log.error(pos, "cyclic.inheritance", t);
    1.18          } else if (t.tag == TYPEVAR) {
    1.19              tv = (TypeVar)t;
    1.20 -            seen.add(tv);
    1.21 +            seen = seen.prepend(tv);
    1.22              for (Type b : types.getBounds(tv))
    1.23                  checkNonCyclic1(pos, b, seen);
    1.24          }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/typevars/6804733/T6804733.java	Thu Mar 05 17:24:40 2009 +0000
     2.3 @@ -0,0 +1,35 @@
     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     6804733
    2.30 + * @summary javac generates spourious diagnostics for ill-formed type-variable bounds
    2.31 + * @author  mcimadamore
    2.32 + * @compile/fail/ref=T6804733.out -XDrawDiagnostics T6804733.java
    2.33 + */
    2.34 +
    2.35 +import java.util.ArrayList;
    2.36 +class T6804733<S> extends ArrayList<S> {
    2.37 +    <T extends S & S> void m() {}
    2.38 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/generics/typevars/6804733/T6804733.out	Thu Mar 05 17:24:40 2009 +0000
     3.3 @@ -0,0 +1,2 @@
     3.4 +T6804733.java:34:20: compiler.err.type.var.may.not.be.followed.by.other.bounds
     3.5 +1 error

mercurial