Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(865)

Unified Diff: tests/compiler/dart2js/simple_inferrer_const_closure_default_test.dart

Issue 1320673004: dart2js: Make functions that appear to be unreachable throw. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/compiler/dart2js/mock_libraries.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/simple_inferrer_const_closure_default_test.dart
diff --git a/tests/compiler/dart2js/simple_inferrer_const_closure_default_test.dart b/tests/compiler/dart2js/simple_inferrer_const_closure_default_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e6d2e9210606dfeaca1580bb3d8bb1d653f0250a
--- /dev/null
+++ b/tests/compiler/dart2js/simple_inferrer_const_closure_default_test.dart
@@ -0,0 +1,84 @@
+// Copyright (c) 2014, 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.
+
+import 'package:expect/expect.dart';
+import "package:async_helper/async_helper.dart";
+import 'compiler_helper.dart';
+import 'type_mask_test_helper.dart';
+
+
+
+const String TEST = """
+
+// [defaultFn_i] is called only via [foo_i]'s default value with a small integer.
+
+defaultFn1(a) => a;
+defaultFn2(a) => a;
+defaultFn3(a) => a;
+defaultFn4(a) => a;
+defaultFn5(a) => a;
+defaultFn6(a) => a;
+
+foo1([fn = defaultFn1]) => fn(54);
+foo2({fn: defaultFn2}) => fn(54);
+foo3([fn = defaultFn3]) => fn(54);
+foo4({fn: defaultFn4}) => fn(54);
+foo5([fn = defaultFn5]) => fn(54);
+foo6({fn: defaultFn6}) => fn(54);
+
+main() {
+ // Direct calls.
+ foo1();
+ foo2();
+ // Indirect calls.
+ (foo3)();
+ (foo4)();
+ // Calls via Function.apply.
+ Function.apply(foo5, []);
+ Function.apply(foo6, []);
+}
+""";
+
+
+void main() {
+ Uri uri = new Uri(scheme: 'source');
+ var compiler = compilerFor(TEST, uri);
+ asyncTest(() => compiler.runCompiler(uri).then((_) {
+ var typesInferrer = compiler.typesTask.typesInferrer;
+
+ checkArgument(String functionName, type) {
+ var functionElement = findElement(compiler, functionName);
+ var signature = functionElement.functionSignature;
+ var element = signature.requiredParameterCount > 0
+ ? signature.requiredParameters.first
+ : signature.optionalParameters.first;
+ Expect.equals(type,
+ simplify(typesInferrer.getTypeOfElement(element), compiler),
+ functionName);
+ }
+
+ checkOptionalArgument(String functionName, type) {
+ var functionElement = findElement(compiler, functionName);
+ var signature = functionElement.functionSignature;
+ var element = signature.optionalParameters.first;
+ Expect.equals(type,
+ simplify(typesInferrer.getTypeOfElement(element), compiler),
+ functionName);
+ }
+
+ checkArgument('foo1', compiler.typesTask.functionType); /// 01: ok
+ checkArgument('foo2', compiler.typesTask.functionType); /// 02: ok
+ checkArgument('foo3', compiler.typesTask.functionType); /// 03: ok
+ checkArgument('foo4', compiler.typesTask.functionType); /// 04: ok
+ checkArgument('foo5', compiler.typesTask.functionType); /// 05: ok
+ checkArgument('foo6', compiler.typesTask.functionType); /// 06: ok
+
+ checkArgument('defaultFn1', compiler.typesTask.uint31Type); /// 07: ok
+ checkArgument('defaultFn2', compiler.typesTask.uint31Type); /// 08: ok
+ checkArgument('defaultFn3', compiler.typesTask.uint31Type); /// 09: ok
+ checkArgument('defaultFn4', compiler.typesTask.uint31Type); /// 10: ok
+ checkArgument('defaultFn5', compiler.typesTask.uint31Type); /// 11: ok
+ checkArgument('defaultFn6', compiler.typesTask.uint31Type); /// 12: ok
+ }));
+}
« no previous file with comments | « tests/compiler/dart2js/mock_libraries.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698