scala/scala — pull request #2954 by retronym (2013-09-17 14:14:55+00:00)
Title: Avoid null checks when emitting "".== and SomeModule.==

Although the same the code would be later optimized by -Yconst-opt,
we can offer the same lean byte code to those compiling without that
option by being more discerning when translating ==.

This helps people using bytecode based code coverage tools
such as jacoco that would emit "branch not covered" warnings
for the impossible null check.

Before:
```
scala> class C { (null: Any) match { case Nil => case "" => case _ => } }
defined class C

scala> :javap C

public C();
Code:
Stack=2, Locals=5, Args_size=1
0:	aload_0
1:	invokespecial	#9; //Method java/lang/Object."":()V
4:	aconst_null
5:	astore_1
6:	getstatic	#15; //Field scala/collection/immutable/Nil$.MODULE$:Lscala/collection/immutable/Nil$;
9:	aload_1
10:	astore_2
11:	dup
12:	ifnonnull	23
15:	pop
16:	aload_2
17:	ifnull	30
20:	goto	37
23:	aload_2
24:	invokevirtual	#19; //Method java/lang/Object.equals:(Ljava/lang/Object;)Z
27:	ifeq	37
30:	getstatic	#25; //Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
33:	astore_3
34:	goto	74
37:	ldc	#27; //String
39:	aload_1
40:	astore	4
42:	dup
43:	ifnonnull	55
46:	pop
47:	aload	4
49:	ifnull	63
52:	goto	70
55:	aload	4
57:	invokevirtual	#19; //Method java/lang/Object.equals:(Ljava/lang/Object;)Z
60:	ifeq	70
63:	getstatic	#25; //Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
66:	astore_3
67:	goto	74
70:	getstatic	#25; //Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
73:	astore_3
74:	return
LocalVariableTable:
Start Length Slot Name Signature
```

After:
```
public C();
Code:
Stack=2, Locals=3, Args_size=1
0:	aload_0
1:	invokespecial	#9; //Method java/lang/Object."":()V
4:	aconst_null
5:	astore_1
6:	getstatic	#15; //Field scala/collection/immutable/Nil$.MODULE$:Lscala/collection/immutable/Nil$;
9:	aload_1
10:	invokevirtual	#19; //Method java/lang/Object.equals:(Ljava/lang/Object;)Z
13:	ifeq	23
16:	getstatic	#25; //Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
19:	astore_2
20:	goto	43
23:	ldc	#27; //String
25:	aload_1
26:	invokevirtual	#19; //Method java/lang/Object.equals:(Ljava/lang/Object;)Z
29:	ifeq	39
32:	getstatic	#25; //Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
35:	astore_2
36:	goto	43
39:	getstatic	#25; //Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
42:	astore_2
43:	return
```

Review by @gkossakowski or @JamesIry, /cc @dragoc