From adf4f174f6457ffb78f9a09b81634bb52528d155 Mon Sep 17 00:00:00 2001 From: Srikanth Sankaran Date: Fri, 20 Dec 2024 17:03:29 +0530 Subject: [PATCH] [Switch Expression] yield does not work with bitwise complement ~ * Fixes https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3481 --- .../jdt/internal/compiler/parser/Scanner.java | 1 - .../SwitchExpressionsYieldTest.java | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Scanner.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Scanner.java index 4abc9c7c9d2..7a88fbc3bb8 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Scanner.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Scanner.java @@ -5549,7 +5549,6 @@ int disambiguateYield() { case TokenNameAND: case TokenNameMULTIPLY: case TokenNameOR: - case TokenNameTWIDDLE: case TokenNameDIVIDE: case TokenNameGREATER: case TokenNameLESS: diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java index 9bf6ba054e6..cf82feff8c0 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java @@ -8360,4 +8360,43 @@ public static void main(String[] args) { }, "true"); } + + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3481 + // [Switch Expression] yield does not work with bitwise complement ~ + public void testIssue3481() { + this.runConformTest( + new String[] { + "X.java", + """ + public class X { + int a = switch(0) { + default -> { + yield ~1; + } + }; + int b = switch(0) { + default -> { + int x = 0; + yield ~x; + } + }; + int c = switch (0) { + case 0 -> { + yield ~2; + } + default -> 1; + }; + + { + System.out.println("a = " + a + " b = " + b + " c = " + c); + } + + public static void main(String [] args) { + new X(); + } + } + """ + }, + "a = -2 b = -1 c = -3"); + } } \ No newline at end of file