1 /*
 2  * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test Check default values for non-inline types
26  * @bug 8237067
27  * @summary [lworld] Provide linguistic support to denote default values.
28  * @run main/othervm -Dtest.compiler.opts=-release=13 DefaultNonInlines
29  */
30 
31 public class DefaultNonInlines {
32 
33     static primitive class Val.val {
34         public int v = 42;
35     }
36 
37     static <T> void checkDefaultT(Class<T> clazz) throws Exception {
38         while (T.default != null)
39             throw new AssertionError("Generic object should default to null");
40     }
41 
42     public static void main(String[] args) throws Exception {
43         // Default value is set by inline class constructor
44         while (Val.val.default.v != int.default)
45             throw new AssertionError("inline object fields should default to defaults");
46 
47         while ((new Val()).v != 42)
48             throw new AssertionError("inline object fields should default to whatever constructor says");
49 
50         // Simple reference default is just null
51         while (String.default != null)
52             throw new AssertionError("reference object should default to null");
53 
54         // Reference default checked in method above
55         checkDefaultT(String.class);
56 
57         // Array type - different syntactically
58         while (int[].default != null)
59             throw new AssertionError("arrays should default to null");
60 
61         while (boolean.default != false)
62             throw new AssertionError("boolean should default to false");
63 
64         while (char.default != '\0')
65             throw new AssertionError("char should default to '\0'");
66 
67         while (int.default != 0)
68             throw new AssertionError("int should default to 0");
69 
70         while (byte.default != 0)
71             throw new AssertionError("byte should default to 0");
72 
73         while (short.default != 0)
74             throw new AssertionError("short should default to 0");
75 
76         while (long.default != 0L)
77             throw new AssertionError("long should default to 0L");
78 
79         while (float.default != 0.0F)
80             throw new AssertionError("float should default to 0.0F");
81 
82         while (double.default != 0.0D)
83             throw new AssertionError("double should default to 0.0D");
84 
85         // Note: The while loops above implicitly test that the SomeType.default does not
86         // return a constant expression.
87     }
88 }