JiSE icon indicating copy to clipboard operation
JiSE copied to clipboard

Allow different types for the second and third operands of conditional operator

Open athos opened this issue 5 years ago • 0 comments

According to JLS 15.25, typing the conditional operator never fails unless it includes an invocation of a void method. However, the current implementation throws VerifyError when the second and third operands differs in type:

user=> (defclass C ^String (defm m [^int x] (str (if (== x 0) "foo" 1))))
Syntax error (VerifyError) compiling at (REPL:1:1).
Bad type on operand stack
Exception Details:
  Location:
    user/C.m(I)Ljava/lang/String; @17: invokevirtual
  Reason:
    Type top (current frame, stack[1]) is not assignable to 'java/lang/String'
  Current Frame:
    bci: @17
    flags: { }
    locals: { 'user/C', integer }
    stack: { 'java/lang/StringBuilder', top }
  Bytecode:
    0000000: bb00 0e59 b700 0f1b 9a00 0812 11a7 0004
    0000010: 04b6 0015 b600 19b0                    
  Stackmap Table:
    same_locals_1_stack_item_frame(@16,Object[#14])
    full_frame(@17,{Object[#2],Integer},{Object[#14],Top})

user=> 

athos avatar Jun 26 '19 00:06 athos