test/tools/javac/literals/BadUnderscoreLiterals.java

Tue, 15 Sep 2009 18:36:21 -0700

author
jjg
date
Tue, 15 Sep 2009 18:36:21 -0700
changeset 409
69eaccd3ea85
child 757
c44234f680da
permissions
-rw-r--r--

6860965: Project Coin: binary literals
6860973: Project Coin: Underscores in literals
Summary: [Portions contributed by Bruce Chapman]
Reviewed-by: darcy

jjg@409 1 /*
jjg@409 2 * @test /nodynamiccopyright/
jjg@409 3 * @bug 6860973
jjg@409 4 * @summary Project Coin: underscores in literals
jjg@409 5 *
jjg@409 6 * @compile/fail BadUnderscoreLiterals.java
jjg@409 7 * @compile/fail/ref=BadUnderscoreLiterals.7.out -XDrawDiagnostics BadUnderscoreLiterals.java
jjg@409 8 *
jjg@409 9 * @compile/fail -source 6 BadUnderscoreLiterals.java
jjg@409 10 * @compile/fail/ref=BadUnderscoreLiterals.6.out -XDrawDiagnostics -source 6 BadUnderscoreLiterals.java
jjg@409 11 */
jjg@409 12
jjg@409 13 public class BadUnderscoreLiterals {
jjg@409 14 int valid = 1_1; // valid literal; illegal in -source 6
jjg@409 15
jjg@409 16 // test zero
jjg@409 17 int z1 = _0; // valid (but undefined) variable
jjg@409 18 int z2 = 0_; // trailing underscore
jjg@409 19
jjg@409 20 // test simple (decimal) integers
jjg@409 21 int i1 = _1_2_3; // valid (but undefined) variable
jjg@409 22 int i2 = 1_2_3_; // trailing underscore
jjg@409 23
jjg@409 24 // test binary integers
jjg@409 25 int b1 = 0b_0; // leading underscore after radix
jjg@409 26 int b2 = 0b0_; // trailing underscore
jjg@409 27
jjg@409 28 // test hexadecimal integers
jjg@409 29 int x1 = 0x_0; // leading underscore after radix
jjg@409 30 int x2 = 0x0_; // trailing underscore
jjg@409 31
jjg@409 32 // test floating point numbers
jjg@409 33 float f1 = 0_.1; // trailing underscore before decimal point
jjg@409 34 float f2 = 0._1; // leading underscore after decimal point
jjg@409 35 float f3 = 0.1_; // trailing underscore
jjg@409 36 float f4 = 0.1_e0; // trailing underscore before exponent
jjg@409 37 float f5 = 0e_1; // leading underscore in exponent
jjg@409 38 float f6 = 0e1_; // trailing underscore in exponent
jjg@409 39
jjg@409 40 // hexadecimal floating point
jjg@409 41 float xf1 = 0x_0.1p0; // leading underscore after radix
jjg@409 42 float xf2 = 0x0_.1p0; // trailing underscore before decimal point
jjg@409 43 float xf3 = 0x0._1p0; // leading underscore after decimal point
jjg@409 44 float xf4 = 0x0.1_p0; // trailing underscore before exponent
jjg@409 45 float xf5 = 0x0p_1; // leading underscore after exponent
jjg@409 46 float xf6 = 0x0p1_; // trailing underscore
jjg@409 47 }
jjg@409 48

mercurial