1 /*
 2  * Copyright (c) 2018, 2024, 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  * @ignore Fix JDK-8328438
26  * @test
27  * @summary Test basic verifier assignability of inline types.
28  * @enablePreview
29  * @compile VTAssignability.java
30  * @run main/othervm -Xverify:remote VTAssignability
31  */
32 
33 // Test that an inline type is assignable to itself, to java.lang.Object,
34 // and to an interface,
35 //
36 interface II { }
37 
38 public primitive final class VTAssignability implements II {
39     final int x;
40     final int y;
41 
42     public VTAssignability(int x, int y) {
43         this.x = x;
44         this.y = y;
45     }
46 
47     public int getX() { return x; }
48     public int getY() { return y; }
49 
50     public boolean isSameVTAssignability(VTAssignability that) {
51         return this.getX() == that.getX() && this.getY() == that.getY();
52     }
53 
54     public boolean equals(Object o) {
55         if(o instanceof VTAssignability) {
56             return ((VTAssignability)o).x == x &&  ((VTAssignability)o).y == y;
57         } else {
58             return false;
59         }
60     }
61 
62     public void takesInterface(II i) {
63         System.out.println("Test passes!!");
64     }
65 
66     public static void main(String[] args) {
67         VTAssignability a = new VTAssignability(3, 4);
68         VTAssignability b = new VTAssignability(2, 4);
69 
70         // Test assignability of an inline type to itself.
71         boolean res = a.isSameVTAssignability(b);
72 
73         // Test assignability of an inline type to java.lang.Object.
74         res = b.equals(a);
75 
76         // Test assignability of an inline type to an interface.
77         a.takesInterface(b);
78     }
79 }