optimistic_assignment_check_type.js revision 949:fca4db1360f7
1228753Smm/* 2228753Smm * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3228753Smm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4228753Smm * 5228753Smm * This code is free software; you can redistribute it and/or modify it 6228753Smm * under the terms of the GNU General Public License version 2 only, as 7228753Smm * published by the Free Software Foundation. 8228753Smm * 9228753Smm * This code is distributed in the hope that it will be useful, but WITHOUT 10228753Smm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11228753Smm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12228753Smm * version 2 for more details (a copy is included in the LICENSE file that 13228753Smm * accompanied this code). 14228753Smm * 15228753Smm * You should have received a copy of the GNU General Public License version 16228753Smm * 2 along with this work; if not, write to the Free Software Foundation, 17228753Smm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18228753Smm * 19228753Smm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20228753Smm * or visit www.oracle.com if you need additional information or have any 21228753Smm * questions. 22228753Smm */ 23228753Smm 24228753Smm/** 25228753Smm * @test 26228753Smm * @bug 8036987, 8037572 27228763Smm * @summary Implement tests that checks static types in the compiled code 28228753Smm * @option --optimistic-types=true 29248616Smm * @run 30228753Smm */ 31228753Smm 32228753Smmvar inspect = Java.type("jdk.nashorn.test.tools.StaticTypeInspector").inspect 33248616Smmvar a = b = 3; 34248616Smmvar c; 35248616Smmvar x = { a: 2, b:1, c: 7, d: -1, e: 1} 36228753Smmvar y = { a: undefined, b: undefined} 37248616Smm 38228753Smm// Testing assignment operators 39228753Smm//-- Global variable 40228753Smmprint(inspect(a=c, "global int assignment to global variable")) 41228753Smmprint(inspect(a=b, "undefined assignment to global int")) 42228753Smmprint(inspect(a=y.a, "global int assignment to undefined")) 43228753Smmprint(inspect(a+=b, "undefined addition assignment to global int")) 44228753Smmprint(inspect(b=b+b, "global int addition global int")) 45228753Smmprint(inspect(b+= y.a, "global int addition assignment undefined")) 46228753Smm//--Local variable 47228753Smmprint(inspect(x.a+= y.a, "local int addition assignment local undefined")) 48228753Smmprint(inspect(x.b=y.a, "local int assignment to undefined")) 49228753Smmprint(inspect(y.a+=y.a, "local undefined addition assignment local undefined")) 50228753Smmprint(inspect(x.c-=x.d, "local int substraction assignment local int")) 51232153Smmprint(inspect(x.c*=x.d, "local int multiplication assignment local int")) 52228753Smmprint(inspect(x.c/=x.d, "local int division assignment local int")) 53228753Smmprint(inspect(y.b=x.c, "local undefined assignment to local int")) 54228753Smmprint(inspect(y.c=x.c, "local boolean assignment to local int")) 55228753Smm