Add test for static tear-off

- to document the change (for the better) with CFE constant

Change-Id: I9b6673497fe07ccd4f92fc4c22df0ae3205f72a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99152
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart
index 85a0f55..7070b01 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -3117,7 +3117,10 @@
             sourceInformation));
       }
     } else {
-      MemberEntity member = _elementMap.getMember(staticTarget);
+      // TODO(johnniwinther): This is a constant tear off, so we should have
+      // created a constant value instead. Remove this case when we use CFE
+      // constants.
+      FunctionEntity member = _elementMap.getMember(staticTarget);
       push(new HStatic(member, _typeInferenceMap.getInferredTypeOf(member),
           sourceInformation));
     }
diff --git a/pkg/compiler/lib/src/ssa/nodes.dart b/pkg/compiler/lib/src/ssa/nodes.dart
index fe5bbfd..c6e5a6d 100644
--- a/pkg/compiler/lib/src/ssa/nodes.dart
+++ b/pkg/compiler/lib/src/ssa/nodes.dart
@@ -3077,8 +3077,12 @@
   accept(HVisitor visitor) => visitor.visitThrow(this);
 }
 
+// TODO(johnniwinther): Change this to a "HStaticLoad" of a field when we use
+// CFE constants. It has been used for static tear-offs even though these should
+// have been constants.
 class HStatic extends HInstruction {
   final MemberEntity element;
+
   HStatic(this.element, AbstractValue type, SourceInformation sourceInformation)
       : super(<HInstruction>[], type) {
     assert(element != null);
diff --git a/tests/compiler/dart2js/codegen/model_data/static_tearoff.dart b/tests/compiler/dart2js/codegen/model_data/static_tearoff.dart
new file mode 100644
index 0000000..75fa653
--- /dev/null
+++ b/tests/compiler/dart2js/codegen/model_data/static_tearoff.dart
@@ -0,0 +1,32 @@
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class I1 {}
+
+class I2 {}
+
+class A implements I1, I2 {}
+
+class B implements I1, I2 {}
+
+/*element: foo:params=1*/
+@pragma('dart2js:noInline')
+void foo(I1 x) {}
+
+/*element: bar:params=1*/
+@pragma('dart2js:noInline')
+void bar(I2 x) {}
+
+/*strong.element: main:calls=[call$1(new F.A()),call$1(new F.B()),foo(1),foo(1),main__bar$closure(0),main__bar$closure(0)],params=0*/
+/*omit.element: main:calls=[call$1(new F.A()),call$1(new F.B()),foo(1),foo(1),main__bar$closure(0),main__bar$closure(0)],params=0*/
+/*strongConst.element: main:calls=[bar(1),bar(1),foo(1),foo(1)],params=0*/
+/*omitConst.element: main:calls=[bar(1),bar(1),foo(1),foo(1)],params=0*/
+main() {
+  dynamic f = bar;
+
+  foo(new A());
+  foo(new B());
+  f(new A());
+  f(new B());
+}