scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

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

Open som-snytt opened 5 months ago

som-snytt commented 5 months ago

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 commented 5 months ago

also why is github ticket title case so big.

som-snytt commented 5 months ago

I would have checked dotty if they had :javap.