mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
4741726: allow Object += String
Remove code in line with restriction removed from JLS Reviewed-by: mcimadamore
This commit is contained in:
parent
e82f625583
commit
7c8027dace
2 changed files with 17 additions and 21 deletions
|
@ -1609,18 +1609,11 @@ public class Attr extends JCTree.Visitor {
|
||||||
tree.getTag() - JCTree.ASGOffset,
|
tree.getTag() - JCTree.ASGOffset,
|
||||||
owntype,
|
owntype,
|
||||||
operand);
|
operand);
|
||||||
if (types.isSameType(operator.type.getReturnType(), syms.stringType)) {
|
|
||||||
// String assignment; make sure the lhs is a string
|
|
||||||
chk.checkType(tree.lhs.pos(),
|
|
||||||
owntype,
|
|
||||||
syms.stringType);
|
|
||||||
} else {
|
|
||||||
chk.checkDivZero(tree.rhs.pos(), operator, operand);
|
chk.checkDivZero(tree.rhs.pos(), operator, operand);
|
||||||
chk.checkCastable(tree.rhs.pos(),
|
chk.checkCastable(tree.rhs.pos(),
|
||||||
operator.type.getReturnType(),
|
operator.type.getReturnType(),
|
||||||
owntype);
|
owntype);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
result = check(tree, owntype, VAL, pkind, pt);
|
result = check(tree, owntype, VAL, pkind, pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,14 +23,17 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4642850
|
* @bug 4741726
|
||||||
* @summary compiler allows Object += String
|
* @summary allow Object += String
|
||||||
* @author gafter
|
|
||||||
*
|
|
||||||
* @compile/fail ObjectAppend.java
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ObjectAppend {{
|
public class StringConversion2
|
||||||
Object o = null;
|
{
|
||||||
o += "string";
|
public static void main(String[] args) {
|
||||||
}}
|
Object o = "Hello ";
|
||||||
|
String s = "World!";
|
||||||
|
o += s;
|
||||||
|
if (!o.equals("Hello World!"))
|
||||||
|
throw new Error("test failed");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue