Lambda Currying #326

Closed
opened 2024-04-25 19:11:34 +00:00 by i21023 · 0 comments
Collaborator

Folgender Code compiliert, wirft aber einen Runtime Error, wenn er aus einer Hilfsklasse heraus aufgerufen wird:

import java.lang.Integer;

public class Foo{
   main(){
      var func = x -> y -> x*y;
      return func.apply(3).apply(4);
   }
}
public class Start {
   public static void main(String[] args) {
      System.out.println(new Foo().main());
   }
}
$ java Start
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    Foo.lambda$0(Ljava/lang/Object;)LFun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$; @2: invokedynamic
  Reason:
    Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'java/lang/Integer'
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'Foo', 'java/lang/Object' }
    stack: { 'Foo', 'java/lang/Object' }
  Bytecode:
    0000000: 2a2b ba00 2900 00b0                    

        at Start.main(Start.java:7)
Folgender Code compiliert, wirft aber einen Runtime Error, wenn er aus einer Hilfsklasse heraus aufgerufen wird: ```java import java.lang.Integer; public class Foo{ main(){ var func = x -> y -> x*y; return func.apply(3).apply(4); } } ``` ```java public class Start { public static void main(String[] args) { System.out.println(new Foo().main()); } } ``` ``` $ java Start Exception in thread "main" java.lang.VerifyError: Bad type on operand stack Exception Details: Location: Foo.lambda$0(Ljava/lang/Object;)LFun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$; @2: invokedynamic Reason: Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'java/lang/Integer' Current Frame: bci: @2 flags: { } locals: { 'Foo', 'java/lang/Object' } stack: { 'Foo', 'java/lang/Object' } Bytecode: 0000000: 2a2b ba00 2900 00b0 at Start.main(Start.java:7) ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: JavaTX/JavaCompilerCore#326
No description provided.