eclipse-jdt / eclipse.jdt.ui

Eclipse Public License 2.0
35 stars 86 forks source link

Inline existing method in switch expression should not add yield keyword when case is without block #1439

Closed NolwennD closed 2 months ago

NolwennD commented 2 months ago

Hello,

In the code below, when I inline the hello method, yield is added and syntax is not valid. Inline works well when there is a block.

public class FailedInline {

  static String beforeInline(FizzBuzz fizzBuzz) {
    return switch (fizzBuzz) {
      case FIZZ -> hello();
      case BUZZ -> hello();
    };
  }

  static String afterInline(FizzBuzz fizzBuzz) {
    return switch (fizzBuzz) {
      case FIZZ -> hello();
      case BUZZ -> yield "World"; 
      //case BUZZ -> "World";  <– expected result
    };
  }
  enum FizzBuzz {FIZZ, BUZZ}

  private static String hello() {
    return "World";
  }
}

Eclipse version : Version: 2024-03 (4.31.0) Build id: 20240307-1437