Skip to content

Instantly share code, notes, and snippets.

@EncodePanda
Created December 8, 2017 21:51
Show Gist options
  • Select an option

  • Save EncodePanda/bbd8604b7edb2881a7716ccdeecbc42e to your computer and use it in GitHub Desktop.

Select an option

Save EncodePanda/bbd8604b7edb2881a7716ccdeecbc42e to your computer and use it in GitHub Desktop.

So this

class TryProveDanielWrong {

  def attempt1(pf1: PartialFunction[Int, Boolean], pf2:PartialFunction[Int, Boolean]): Boolean =
    (pf1.isDefinedAt(10), pf2.isDefinedAt(10)) match {
      case  (true, true) => true
      case (true, false) => pf1(10)
      case (false, true) => pf2(10)
      case (false, false) => false
    }

}

compiles down to this

Compiled from "TryProveDanielWrong.scala"
public class TryProveDanielWrong {
  public boolean attempt1(scala.PartialFunction<java.lang.Object, java.lang.Object>, scala.PartialFunction<java.lang.Object, java.lang.Object>);
    Code:
       0: new           #14                 // class scala/Tuple2$mcZZ$sp
       3: dup
       4: aload_1
       5: bipush        10
       7: invokestatic  #20                 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
      10: invokeinterface #26,  2           // InterfaceMethod scala/PartialFunction.isDefinedAt:(Ljava/lang/Object;)Z
      15: aload_2
      16: bipush        10
      18: invokestatic  #20                 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
      21: invokeinterface #26,  2           // InterfaceMethod scala/PartialFunction.isDefinedAt:(Ljava/lang/Object;)Z
      26: invokespecial #30                 // Method scala/Tuple2$mcZZ$sp."<init>":(ZZ)V
      29: astore        4
      31: aload         4
      33: ifnull        70
      36: aload         4
      38: invokevirtual #36                 // Method scala/Tuple2._1$mcZ$sp:()Z
      41: istore        5
      43: aload         4
      45: invokevirtual #39                 // Method scala/Tuple2._2$mcZ$sp:()Z
      48: istore        6
      50: iconst_1
      51: iload         5
      53: if_icmpne     67
      56: iconst_1
      57: iload         6
      59: if_icmpne     67
      62: iconst_1
      63: istore_3
      64: goto          223
      67: goto          73
      70: goto          73
      73: aload         4
      75: ifnull        119
      78: aload         4
      80: invokevirtual #36                 // Method scala/Tuple2._1$mcZ$sp:()Z
      83: istore        7
      85: aload         4
      87: invokevirtual #39                 // Method scala/Tuple2._2$mcZ$sp:()Z
      90: istore        8
      92: iconst_1
      93: iload         7
      95: if_icmpne     116
      98: iconst_0
      99: iload         8
     101: if_icmpne     116
     104: aload_1
     105: bipush        10
     107: invokeinterface #43,  2           // InterfaceMethod scala/PartialFunction.apply$mcZI$sp:(I)Z
     112: istore_3
     113: goto          223
     116: goto          122
     119: goto          122
     122: aload         4
     124: ifnull        168
     127: aload         4
     129: invokevirtual #36                 // Method scala/Tuple2._1$mcZ$sp:()Z
     132: istore        9
     134: aload         4
     136: invokevirtual #39                 // Method scala/Tuple2._2$mcZ$sp:()Z
     139: istore        10
     141: iconst_0
     142: iload         9
     144: if_icmpne     165
     147: iconst_1
     148: iload         10
     150: if_icmpne     165
     153: aload_2
     154: bipush        10
     156: invokeinterface #43,  2           // InterfaceMethod scala/PartialFunction.apply$mcZI$sp:(I)Z
     161: istore_3
     162: goto          223
     165: goto          171
     168: goto          171
     171: aload         4
     173: ifnull        210
     176: aload         4
     178: invokevirtual #36                 // Method scala/Tuple2._1$mcZ$sp:()Z
     181: istore        11
     183: aload         4
     185: invokevirtual #39                 // Method scala/Tuple2._2$mcZ$sp:()Z
     188: istore        12
     190: iconst_0
     191: iload         11
     193: if_icmpne     207
     196: iconst_0
     197: iload         12
     199: if_icmpne     207
     202: iconst_0
     203: istore_3
     204: goto          223
     207: goto          213
     210: goto          213
     213: new           #45                 // class scala/MatchError
     216: dup
     217: aload         4
     219: invokespecial #48                 // Method scala/MatchError."<init>":(Ljava/lang/Object;)V
     222: athrow
     223: iload_3
     224: ireturn

  public TryProveDanielWrong();
    Code:
       0: aload_0
       1: invokespecial #54                 // Method java/lang/Object."<init>":()V
       4: return
}

Where is the "scary" part?

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