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

Side by Side Diff: tests/compiler/dart2js/simple_inferrer_and_or_test.dart

Issue 182373002: Fix bad type-inferrence for logical expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use lhs of &&. Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import "package:async_helper/async_helper.dart"; 6 import "package:async_helper/async_helper.dart";
7 import 'compiler_helper.dart'; 7 import 'compiler_helper.dart';
8 import 'type_mask_test_helper.dart'; 8 import 'type_mask_test_helper.dart';
9 9
10 const String TEST = """ 10 const String TEST = """
(...skipping 27 matching lines...) Expand all
38 ((a = 52) == true) && ((a = new X()) == true); 38 ((a = 52) == true) && ((a = new X()) == true);
39 return a; 39 return a;
40 } 40 }
41 41
42 returnDyn6() { 42 returnDyn6() {
43 var a; 43 var a;
44 a = a == 54 ? 'foo' : new X(); 44 a = a == 54 ? 'foo' : new X();
45 return a; 45 return a;
46 } 46 }
47 47
48 returnDyn7b(x) => x;
49
50 returnDyn7() {
51 var a = "foo";
52 if (a.length == 3) a = 52;
53 if ((a is int) || (a is String && true)) returnDyn7b(a);
54 return a;
55 }
56
57 returnDyn8(x) => x;
58
59 test8() {
60 var a = "foo";
61 if (a.length == 3) a = 52;
62 if ((false && a is! String) || returnDyn8(a)) return a;
63 }
64
65 returnDyn9(x) => x;
66
67 test9() {
68 var a = "foo";
69 if (a.length == 3) a = 52;
70 if (!(a is bool && a is bool)) returnDyn9(a);
71 }
72
73 returnString(x) => x;
74
75 test10() {
76 var a = "foo";
77 if (a.length == 3) a = 52;
78 if (!(a is num) && a is String) returnString(a);
79 }
80
48 main() { 81 main() {
49 returnDyn1(); 82 returnDyn1();
50 returnDyn2(); 83 returnDyn2();
51 returnDyn3(); 84 returnDyn3();
52 returnDyn4(); 85 returnDyn4();
53 returnDyn5(); 86 returnDyn5();
54 returnDyn6(); 87 returnDyn6();
88 returnDyn7();
89 test8();
90 test9();
91 test10();
55 } 92 }
56 """; 93 """;
57 94
58 95
59 void main() { 96 void main() {
60 Uri uri = new Uri(scheme: 'source'); 97 Uri uri = new Uri(scheme: 'source');
61 var compiler = compilerFor(TEST, uri); 98 var compiler = compilerFor(TEST, uri);
62 asyncTest(() => compiler.runCompiler(uri).then((_) { 99 asyncTest(() => compiler.runCompiler(uri).then((_) {
63 var typesInferrer = compiler.typesTask.typesInferrer; 100 var typesInferrer = compiler.typesTask.typesInferrer;
64 101
65 checkReturn(String name, type) { 102 checkReturn(String name, type) {
66 var element = findElement(compiler, name); 103 var element = findElement(compiler, name);
67 Expect.equals(type, 104 Expect.equals(type,
68 simplify(typesInferrer.getReturnTypeOfElement(element), compiler)); 105 simplify(typesInferrer.getReturnTypeOfElement(element), compiler));
69 } 106 }
70 107
71 var subclassOfInterceptor = 108 var subclassOfInterceptor =
72 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); 109 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
73 110
74 checkReturn('returnDyn1', subclassOfInterceptor); 111 checkReturn('returnDyn1', subclassOfInterceptor);
75 checkReturn('returnDyn2', subclassOfInterceptor); 112 checkReturn('returnDyn2', subclassOfInterceptor);
76 checkReturn('returnDyn3', subclassOfInterceptor); 113 checkReturn('returnDyn3', subclassOfInterceptor);
77 checkReturn('returnDyn4', compiler.typesTask.dynamicType.nonNullable()); 114 checkReturn('returnDyn4', compiler.typesTask.dynamicType.nonNullable());
78 checkReturn('returnDyn5', compiler.typesTask.dynamicType.nonNullable()); 115 checkReturn('returnDyn5', compiler.typesTask.dynamicType.nonNullable());
79 checkReturn('returnDyn6', compiler.typesTask.dynamicType.nonNullable()); 116 checkReturn('returnDyn6', compiler.typesTask.dynamicType.nonNullable());
117 checkReturn('returnDyn7', subclassOfInterceptor);
118 checkReturn('returnDyn7b', subclassOfInterceptor);
119 checkReturn('returnDyn8', subclassOfInterceptor);
120 checkReturn('returnDyn9', subclassOfInterceptor);
121 checkReturn('returnString', compiler.typesTask.stringType);
80 })); 122 }));
81 } 123 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/inferrer/inferrer_visitor.dart ('k') | tests/language/logical_expression2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698