mambastudio opened a new issue, #7388:
URL: https://github.com/apache/netbeans/issues/7388

   ### Apache NetBeans version
   
   Apache NetBeans 21
   
   ### What happened
   
   Seems using var in pattern matching when implementing Algebraic Data Type 
patterns results "_Exception in thread "main" java.lang.RuntimeException: 
Uncompilable code_"
   
   
   ### Language / Project Type / NetBeans Component
   
   _No response_
   
   ### How to reproduce
   
   Seems using var in pattern matching when implementing Algebraic Data Type 
patterns results "_Exception in thread "main" java.lang.RuntimeException: 
Uncompilable code_"
   
   For example, the code below throws the exception when run on netbeans
   
   `public class ADTEvaluation {
          
       sealed interface Expr{}
       
       record ConstExpr(int i) implements Expr{}
       record SumExpr(Expr left, Expr right) implements Expr{}
       
       static int eval(Expr e){
           return switch(e){
               case SumExpr(var a, var b) -> eval(a) + eval(b);
               case ConstExpr(int i) -> i;
               default -> 3;
           };
       }
       
       
       public static void main(String... args)
       {
           var v = new ConstExpr(3);
           
           var x = eval(v);
           System.out.println(x);
           
       }
   }`
   
   But if I change the SumExpr(var a, var b), to SumExpr(ConstExpr a, ConstExpr 
b) in the pattern matching in switch, the following code works
   
   `public class ADTEvaluation {
          
       sealed interface Expr{}
       
       record ConstExpr(int i) implements Expr{}
       record SumExpr(Expr left, Expr right) implements Expr{}
       
       static int eval(Expr e){
           return switch(e){
               case SumExpr(ConstExpr a, ConstExpr b) -> eval(a) + eval(b);
               case ConstExpr(int i) -> i;
               default -> 3;
           };
       }
       
       
       public static void main(String... args)
       {
           var v = new ConstExpr(3);
           
           var x = eval(v);
           System.out.println(x);
           
       }
   }`
   
   I'm running Netbeans 21, using JDK 22. There is no problem if I run the code 
in jdk 22 directly.
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   Windows 10
   
   ### JDK
   
   22
   
   ### Apache NetBeans packaging
   
   Apache NetBeans provided installer
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit a pull request?
   
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to