Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

case true => case false => should be case true => case _ => #12934

Open
som-snytt opened this issue Jan 22, 2024 · 2 comments
Open

case true => case false => should be case true => case _ => #12934

som-snytt opened this issue Jan 22, 2024 · 2 comments

Comments

@som-snytt
Copy link

Reproduction steps

Scala version: 2.13.12

under -opt:local for basic hygiene, an exhaustively enumerated match should be the same as the match with a default wildcard case.

scala> def f(b: Boolean) = (b) match { case true => 42 case false => 27 }
def f(b: Boolean): Int

scala> :javap #f
  public int f(boolean);
    descriptor: (Z)I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=2, args_size=2
         0: iconst_1
         1: iload_1
         2: if_icmpne     8
         5: bipush        42
         7: ireturn
         8: iconst_0
         9: iload_1
        10: if_icmpne     16
        13: bipush        27
        15: ireturn
        16: new           #17                 // class scala/MatchError
        19: dup
        20: iload_1
        21: invokestatic  #23                 // Method scala/runtime/BoxesRunTime.boxToBoolean:(Z)Ljava/lang/Boolean;
        24: invokespecial #27                 // Method scala/MatchError."<init>":(Ljava/lang/Object;)V
        27: athrow
      StackMapTable: number_of_entries = 2
        frame_type = 8 /* same */
        frame_type = 7 /* same */
      LineNumberTable:
        line 1: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      28     0  this   L$line3/$read$$iw;
            0      28     1     b   Z
    MethodParameters:
      Name                           Flags
      b                              final

scala> def f(b: Boolean) = (b) match { case true => 42 case _ => 27 }
def f(b: Boolean): Int

scala> :javap #f
  public int f(boolean);
    descriptor: (Z)I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=2
         0: iconst_1
         1: iload_1
         2: if_icmpne     8
         5: bipush        42
         7: ireturn
         8: bipush        27
        10: ireturn
      StackMapTable: number_of_entries = 1
        frame_type = 8 /* same */
      LineNumberTable:
        line 1: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      11     0  this   L$line4/$read$$iw;
            0      11     1     b   Z
    MethodParameters:
      Name                           Flags
      b                              final

scala>

Problem

The matches should be in every way the same. We know the semantics of false.==. Similarly for enums. I didn't check dotty.

@som-snytt som-snytt changed the title case true => case false => should be the same as case true => case _ => case true => case false => should be case true => case _ => Jan 22, 2024
@som-snytt
Copy link
Author

also why is github ticket title case so big.

@som-snytt
Copy link
Author

I would have checked dotty if they had :javap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants