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

Side by Side Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 2667343005: Infer Null for return type of functions with empty returns. (Closed)
Patch Set: Address comments, fix 28630, ddc expectations Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer.test.src.task.strong.checker_test; 5 library analyzer.test.src.task.strong.checker_test;
6 6
7 import 'package:test_reflective_loader/test_reflective_loader.dart'; 7 import 'package:test_reflective_loader/test_reflective_loader.dart';
8 8
9 import 'strong_test_helper.dart'; 9 import 'strong_test_helper.dart';
10 10
(...skipping 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 // function typed formal 2382 // function typed formal
2383 void ftf0(void x(/*error:IMPLICIT_DYNAMIC_PARAMETER*/y)) {} 2383 void ftf0(void x(/*error:IMPLICIT_DYNAMIC_PARAMETER*/y)) {}
2384 void ftf1(void x(int y)) {} 2384 void ftf1(void x(int y)) {}
2385 '''); 2385 ''');
2386 check(implicitDynamic: false); 2386 check(implicitDynamic: false);
2387 } 2387 }
2388 2388
2389 void test_implicitDynamic_return() { 2389 void test_implicitDynamic_return() {
2390 addFile(r''' 2390 addFile(r'''
2391 // function 2391 // function
2392 /*error:IMPLICIT_DYNAMIC_RETURN*/f0() {} 2392 /*error:IMPLICIT_DYNAMIC_RETURN*/f0() {return f0();}
2393 dynamic f1() { return 42; } 2393 dynamic f1() { return 42; }
2394 2394
2395 // nested function 2395 // nested function
2396 void main() { 2396 void main() {
2397 /*error:IMPLICIT_DYNAMIC_RETURN*/g0() {} 2397 /*error:IMPLICIT_DYNAMIC_RETURN*/g0() {return g0();}
2398 dynamic g1() { return 42; } 2398 dynamic g1() { return 42; }
2399 } 2399 }
2400 2400
2401 // methods 2401 // methods
2402 class B { 2402 class B {
2403 int m1() => 42; 2403 int m1() => 42;
2404 } 2404 }
2405 class C extends B { 2405 class C extends B {
2406 /*error:IMPLICIT_DYNAMIC_RETURN*/m0() => 123; 2406 /*error:IMPLICIT_DYNAMIC_RETURN*/m0() => 123;
2407 m1() => 123; 2407 m1() => 123;
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 : g = f ?? _alwaysTrue; 3239 : g = f ?? _alwaysTrue;
3240 C.a() : g = _alwaysTrue; 3240 C.a() : g = _alwaysTrue;
3241 } 3241 }
3242 '''); 3242 ''');
3243 } 3243 }
3244 3244
3245 void test_optionalParams() { 3245 void test_optionalParams() {
3246 // Regression test for https://github.com/dart-lang/sdk/issues/26155 3246 // Regression test for https://github.com/dart-lang/sdk/issues/26155
3247 checkFile(r''' 3247 checkFile(r'''
3248 void takesF(void f(int x)) { 3248 void takesF(void f(int x)) {
3249 takesF(/*info:INFERRED_TYPE_CLOSURE,info:INFERRED_TYPE_CLOSURE*/([x]) { bool z = x.isEven; }); 3249 takesF(/*info:INFERRED_TYPE_CLOSURE,
3250 takesF(/*info:INFERRED_TYPE_CLOSURE*/(y) { bool z = y.isEven; }); 3250 info:INFERRED_TYPE_CLOSURE*/([x]) { bool z = x.isEven; });
3251 takesF(/*info:INFERRED_TYPE_CLOSURE,
3252 info:INFERRED_TYPE_CLOSURE*/(y) { bool z = y.isEven; });
3251 } 3253 }
3252 '''); 3254 ''');
3253 } 3255 }
3254 3256
3255 void test_overrideNarrowsType() { 3257 void test_overrideNarrowsType() {
3256 addFile(r''' 3258 addFile(r'''
3257 class A {} 3259 class A {}
3258 class B extends A {} 3260 class B extends A {}
3259 3261
3260 abstract class C { 3262 abstract class C {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 void baz2(dynamic x) => null; 3700 void baz2(dynamic x) => null;
3699 Null baz3(String x) => null; 3701 Null baz3(String x) => null;
3700 void test() { 3702 void test() {
3701 foo(baz1); 3703 foo(baz1);
3702 foo(baz2); 3704 foo(baz2);
3703 foo(baz3); 3705 foo(baz3);
3704 } 3706 }
3705 '''); 3707 ''');
3706 } 3708 }
3707 3709
3710 void test_tearOffTreatedConsistentlyAsStrictArrowNamedParam() {
3711 checkFile(r'''
3712 typedef void Handler(String x);
3713 void foo({Handler f}) {}
3714
3715 class A {
3716 Null bar1(dynamic x) => null;
3717 void bar2(dynamic x) => null;
3718 Null bar3(String x) => null;
3719 void test() {
3720 foo(f: bar1);
3721 foo(f: bar2);
3722 foo(f: bar3);
3723 }
3724 }
3725
3726
3727 Null baz1(dynamic x) => null;
3728 void baz2(dynamic x) => null;
3729 Null baz3(String x) => null;
3730 void test() {
3731 foo(f: baz1);
3732 foo(f: baz2);
3733 foo(f: baz3);
3734 }
3735 ''');
3736 }
3737
3708 void test_ternaryOperator() { 3738 void test_ternaryOperator() {
3709 checkFile(''' 3739 checkFile('''
3710 abstract class Comparable<T> { 3740 abstract class Comparable<T> {
3711 int compareTo(T other); 3741 int compareTo(T other);
3712 static int compare(Comparable a, Comparable b) => a.compareTo(b); 3742 static int compare(Comparable a, Comparable b) => a.compareTo(b);
3713 } 3743 }
3714 typedef int Comparator<T>(T a, T b); 3744 typedef int Comparator<T>(T a, T b);
3715 3745
3716 typedef bool _Predicate<T>(T value); 3746 typedef bool _Predicate<T>(T value);
3717 3747
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
4115 // Regression test for https://github.com/dart-lang/sdk/issues/25069 4145 // Regression test for https://github.com/dart-lang/sdk/issues/25069
4116 checkFile(''' 4146 checkFile('''
4117 typedef int Foo(); 4147 typedef int Foo();
4118 void foo() {} 4148 void foo() {}
4119 void main () { 4149 void main () {
4120 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); 4150 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo();
4121 } 4151 }
4122 '''); 4152 ''');
4123 } 4153 }
4124 } 4154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698