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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « tests/compiler/dart2js/mock_libraries.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:expect/expect.dart';
6 import "package:async_helper/async_helper.dart";
7 import 'compiler_helper.dart';
8 import 'type_mask_test_helper.dart';
9
10
11
12 const String TEST = """
13
14 // [defaultFn_i] is called only via [foo_i]'s default value with a small integer .
15
16 defaultFn1(a) => a;
17 defaultFn2(a) => a;
18 defaultFn3(a) => a;
19 defaultFn4(a) => a;
20 defaultFn5(a) => a;
21 defaultFn6(a) => a;
22
23 foo1([fn = defaultFn1]) => fn(54);
24 foo2({fn: defaultFn2}) => fn(54);
25 foo3([fn = defaultFn3]) => fn(54);
26 foo4({fn: defaultFn4}) => fn(54);
27 foo5([fn = defaultFn5]) => fn(54);
28 foo6({fn: defaultFn6}) => fn(54);
29
30 main() {
31 // Direct calls.
32 foo1();
33 foo2();
34 // Indirect calls.
35 (foo3)();
36 (foo4)();
37 // Calls via Function.apply.
38 Function.apply(foo5, []);
39 Function.apply(foo6, []);
40 }
41 """;
42
43
44 void main() {
45 Uri uri = new Uri(scheme: 'source');
46 var compiler = compilerFor(TEST, uri);
47 asyncTest(() => compiler.runCompiler(uri).then((_) {
48 var typesInferrer = compiler.typesTask.typesInferrer;
49
50 checkArgument(String functionName, type) {
51 var functionElement = findElement(compiler, functionName);
52 var signature = functionElement.functionSignature;
53 var element = signature.requiredParameterCount > 0
54 ? signature.requiredParameters.first
55 : signature.optionalParameters.first;
56 Expect.equals(type,
57 simplify(typesInferrer.getTypeOfElement(element), compiler),
58 functionName);
59 }
60
61 checkOptionalArgument(String functionName, type) {
62 var functionElement = findElement(compiler, functionName);
63 var signature = functionElement.functionSignature;
64 var element = signature.optionalParameters.first;
65 Expect.equals(type,
66 simplify(typesInferrer.getTypeOfElement(element), compiler),
67 functionName);
68 }
69
70 checkArgument('foo1', compiler.typesTask.functionType); /// 01: ok
71 checkArgument('foo2', compiler.typesTask.functionType); /// 02: ok
72 checkArgument('foo3', compiler.typesTask.functionType); /// 03: ok
73 checkArgument('foo4', compiler.typesTask.functionType); /// 04: ok
74 checkArgument('foo5', compiler.typesTask.functionType); /// 05: ok
75 checkArgument('foo6', compiler.typesTask.functionType); /// 06: ok
76
77 checkArgument('defaultFn1', compiler.typesTask.uint31Type); /// 07: ok
78 checkArgument('defaultFn2', compiler.typesTask.uint31Type); /// 08: ok
79 checkArgument('defaultFn3', compiler.typesTask.uint31Type); /// 09: ok
80 checkArgument('defaultFn4', compiler.typesTask.uint31Type); /// 10: ok
81 checkArgument('defaultFn5', compiler.typesTask.uint31Type); /// 11: ok
82 checkArgument('defaultFn6', compiler.typesTask.uint31Type); /// 12: ok
83 }));
84 }
OLDNEW
« 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