forked from openjdk/amber
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
389 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
test/langtools/tools/javac/diags/examples/MatcherOverloadingAmbiguity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
// key: compiler.err.matcher.overloading.ambiguity | ||
// key: compiler.misc.feature.matchers | ||
// key: compiler.warn.preview.feature.use.plural | ||
// options: --enable-preview -source ${jdk.version} -Xlint:preview | ||
|
||
public class MatcherOverloadingAmbiguity { | ||
private static int test(D o) { | ||
if (o instanceof D(String data, Integer out)) { | ||
return out; | ||
} | ||
return -1; | ||
} | ||
|
||
public record D() { | ||
public __matcher D(Object v, Integer out) { | ||
out = 1; | ||
} | ||
|
||
public __matcher D(CharSequence v, Integer out) { | ||
out = 2; | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
test/langtools/tools/javac/diags/examples/NoCompatibleMatcherFound.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
// key: compiler.err.no.compatible.matcher.found | ||
// key: compiler.err.prob.found.req | ||
// key: compiler.misc.inconvertible.types | ||
// key: compiler.misc.feature.matchers | ||
// key: compiler.warn.preview.feature.use.plural | ||
// options: --enable-preview -source ${jdk.version} -Xlint:preview | ||
|
||
public class NoCompatibleMatcherFound { | ||
private static int test(D o) { | ||
if (o instanceof D(String data, Integer out)) { | ||
return out; | ||
} | ||
return -1; | ||
} | ||
|
||
public record D() { | ||
public __matcher D(Object v1, Float out) { | ||
out = 10.0f; | ||
} | ||
|
||
public __matcher D(Float out, Integer v1) { | ||
out = 2; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
test/langtools/tools/javac/patterns/matchers/OverloadedMatchers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @test | ||
* @enablePreview | ||
* @compile OverloadedMatchers.java | ||
* @run main OverloadedMatchers | ||
*/ | ||
public class OverloadedMatchers { | ||
public static void main(String... args) { | ||
assertEquals( 2, test1(new D())); | ||
assertEquals( 1, test2(new D())); | ||
assertEquals( 1, test3(new D())); | ||
assertEquals( 3, test4(new D())); | ||
assertEquals( 4, test5(new D())); | ||
} | ||
|
||
private static int test1(D o) { | ||
if (o instanceof D(String data, Integer outI)) { | ||
return outI; | ||
} | ||
return -1; | ||
} | ||
|
||
private static int test2(D o) { | ||
if (o instanceof D(Object data, Integer outI)) { | ||
return outI; | ||
} | ||
return -1; | ||
} | ||
|
||
private static int test3(D o) { | ||
if (o instanceof D(Integer data, Integer outI)) { | ||
return outI; | ||
} | ||
return -1; | ||
} | ||
|
||
private static int test4(D o) { | ||
if (o instanceof D(A data, Integer outI)) { | ||
return outI; | ||
} | ||
return -1; | ||
} | ||
|
||
private static Integer test5(D o) { | ||
if (o instanceof D(B data, Integer outI)) { | ||
return outI; | ||
} | ||
return null; | ||
} | ||
|
||
static class A {} | ||
static class B extends A {} | ||
|
||
public record D() { | ||
public __matcher D(Object out, Integer outI) { | ||
out = 42; | ||
outI = 1; | ||
} | ||
|
||
public __matcher D(String out, Integer outI) { | ||
out = "2"; | ||
outI = 2; | ||
} | ||
|
||
public __matcher D(A out, Integer outI) { | ||
out = new A(); | ||
outI = 3; | ||
} | ||
|
||
public __matcher D(B out, Integer outI) { | ||
out = new B(); | ||
outI = 4; | ||
} | ||
} | ||
|
||
private static void assertEquals(int expected, int actual) { | ||
if (!Objects.equals(expected, actual)) { | ||
throw new AssertionError("Expected: " + expected + ", but got: " + actual); | ||
} | ||
} | ||
} |
Oops, something went wrong.