6869075: regression: javac crashes when compiling compound string assignment with generics

Tue, 11 Aug 2009 01:13:42 +0100

author
mcimadamore
date
Tue, 11 Aug 2009 01:13:42 +0100
changeset 360
62fb6cafa93b
parent 359
8227961c64d3
child 361
13902c0c9b83

6869075: regression: javac crashes when compiling compound string assignment with generics
Summary: javac should not add syntehtic cast to the LHS of an assignment expression
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/TransTypes.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/T6869075.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Tue Aug 11 01:13:14 2009 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Tue Aug 11 01:13:42 2009 +0100
     1.3 @@ -631,7 +631,7 @@
     1.4      }
     1.5  
     1.6      public void visitAssignop(JCAssignOp tree) {
     1.7 -        tree.lhs = translate(tree.lhs, tree.operator.type.getParameterTypes().head);
     1.8 +        tree.lhs = translate(tree.lhs, null);
     1.9          tree.rhs = translate(tree.rhs, tree.operator.type.getParameterTypes().tail.head);
    1.10          tree.type = erasure(tree.type);
    1.11          result = tree;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/T6869075.java	Tue Aug 11 01:13:42 2009 +0100
     2.3 @@ -0,0 +1,67 @@
     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     6869075
    2.30 + * @summary regression: javac crashes when compiling compound string assignment with generics
    2.31 + * @author mcimadamore
    2.32 + */
    2.33 +
    2.34 +public class T6869075 {
    2.35 +
    2.36 +    static class Foo<X> {
    2.37 +        X x;
    2.38 +        Foo (X x) {
    2.39 +            this.x = x;
    2.40 +        }
    2.41 +    }
    2.42 +
    2.43 +    static void test1(Foo<String> foo) {
    2.44 +        String start = foo.x;
    2.45 +        equals(foo.x += "foo", start + "foo");
    2.46 +    }
    2.47 +
    2.48 +    static void test2(Foo<String> foo) {
    2.49 +        String start = foo.x;
    2.50 +        equals((foo.x += "foo"), (start + "foo"));
    2.51 +    }
    2.52 +
    2.53 +    static void test3(Foo<String> foo) {
    2.54 +        String start = foo.x;
    2.55 +        equals(((foo.x += "foo")), ((start + "foo")));
    2.56 +    }
    2.57 +
    2.58 +    public static void main(String[] args) {
    2.59 +        test1(new Foo<String>("Hello!"));
    2.60 +        test2(new Foo<String>("Hello!"));
    2.61 +        test3(new Foo<String>("Hello!"));
    2.62 +    }
    2.63 +
    2.64 +    static void equals(String found, String req) {
    2.65 +        if (!found.equals(req)) {
    2.66 +            throw new AssertionError("Error (expected: "+ req +
    2.67 +                                     " - found: " + found + ")");
    2.68 +        }
    2.69 +    }
    2.70 +}
    2.71 \ No newline at end of file

mercurial