OLD | NEW |
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 /// General type checking tests | 5 /// General type checking tests |
6 library dev_compiler.test.checker_test; | 6 library dev_compiler.test.checker_test; |
7 | 7 |
8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
9 | 9 |
10 import 'package:dev_compiler/src/testing.dart'; | 10 import 'package:dev_compiler/src/testing.dart'; |
(...skipping 21 matching lines...) Expand all Loading... |
32 // it requires inference to work because of dartbug.com/23381 | 32 // it requires inference to work because of dartbug.com/23381 |
33 SplayTreeMap([int compare(K key1, K key2), | 33 SplayTreeMap([int compare(K key1, K key2), |
34 bool isValidKey(potentialKey)]) { | 34 bool isValidKey(potentialKey)]) { |
35 : _comparator = /*warning:DownCastComposite*/(compare == null) ? Com
parable.compare : compare, | 35 : _comparator = /*warning:DownCastComposite*/(compare == null) ? Com
parable.compare : compare, |
36 _validKey = /*info:InferredType should be pass*/(isValidKey != nul
l) ? isValidKey : ((v) => true); | 36 _validKey = /*info:InferredType should be pass*/(isValidKey != nul
l) ? isValidKey : ((v) => true); |
37 _Predicate<Object> _v = /*warning:DownCastComposite*/(isValidKey !
= null) ? isValidKey : ((v) => true); | 37 _Predicate<Object> _v = /*warning:DownCastComposite*/(isValidKey !
= null) ? isValidKey : ((v) => true); |
38 _v = /*info:InferredType should be pass*/(isValidKey != null) ? _v
: ((v) => true); | 38 _v = /*info:InferredType should be pass*/(isValidKey != null) ? _v
: ((v) => true); |
39 } | 39 } |
40 } | 40 } |
41 void main() { | 41 void main() { |
| 42 Object obj = 42; |
| 43 dynamic dyn = 42; |
| 44 int i = 42; |
| 45 |
| 46 // Check the boolean conversion of the condition. |
| 47 print((/*severe:StaticTypeError*/i) ? false : true); |
| 48 print((/*warning:DownCastImplicit*/obj) ? false : true); |
| 49 print((/*info:DynamicCast*/dyn) ? false : true); |
42 } | 50 } |
43 ''' | 51 ''' |
44 }); | 52 }); |
45 }); | 53 }); |
46 | 54 |
| 55 test('if/for/do/while statements use boolean conversion', () => testChecker({ |
| 56 '/main.dart': ''' |
| 57 main() { |
| 58 dynamic d = 42; |
| 59 Object obj = 42; |
| 60 int i = 42; |
| 61 bool b = false; |
| 62 |
| 63 if (b) {} |
| 64 if (/*info:DynamicCast*/dyn) {} |
| 65 if (/*warning:DownCastImplicit*/obj) {} |
| 66 if (/*severe:StaticTypeError*/i) {} |
| 67 |
| 68 while (b) {} |
| 69 while (/*info:DynamicCast*/dyn) {} |
| 70 while (/*warning:DownCastImplicit*/obj) {} |
| 71 while (/*severe:StaticTypeError*/i) {} |
| 72 |
| 73 do {} while (b); |
| 74 do {} while (/*info:DynamicCast*/dyn); |
| 75 do {} while (/*warning:DownCastImplicit*/obj); |
| 76 do {} while (/*severe:StaticTypeError*/i); |
| 77 |
| 78 for (;b;) {} |
| 79 for (;/*info:DynamicCast*/dyn;) {} |
| 80 for (;/*warning:DownCastImplicit*/obj;) {} |
| 81 for (;/*severe:StaticTypeError*/i;) {} |
| 82 } |
| 83 ''' |
| 84 })); |
| 85 |
47 test('dynamic invocation', () { | 86 test('dynamic invocation', () { |
48 testChecker({ | 87 testChecker({ |
49 '/main.dart': ''' | 88 '/main.dart': ''' |
50 | 89 |
51 class A { | 90 class A { |
52 dynamic call(dynamic x) => x; | 91 dynamic call(dynamic x) => x; |
53 } | 92 } |
54 class B extends A { | 93 class B extends A { |
55 int call(int x) => x; | 94 int call(int x) => x; |
56 double col(double x) => x; | 95 double col(double x) => x; |
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1917 /*severe:InvalidMethodOverride*/C m2(C value) {} | 1956 /*severe:InvalidMethodOverride*/C m2(C value) {} |
1918 /*severe:InvalidMethodOverride*/A m3(C value) {} | 1957 /*severe:InvalidMethodOverride*/A m3(C value) {} |
1919 C m4(A value) {} | 1958 C m4(A value) {} |
1920 /*severe:InvalidMethodOverride*/m5(value) {} | 1959 /*severe:InvalidMethodOverride*/m5(value) {} |
1921 /*severe:InvalidMethodOverride*/dynamic m6(dynamic value) {} | 1960 /*severe:InvalidMethodOverride*/dynamic m6(dynamic value) {} |
1922 } | 1961 } |
1923 ''' | 1962 ''' |
1924 }, inferFromOverrides: true); | 1963 }, inferFromOverrides: true); |
1925 }); | 1964 }); |
1926 | 1965 |
| 1966 test('unary operators', () => testChecker({ |
| 1967 '/main.dart': ''' |
| 1968 class A { |
| 1969 A operator ~() {} |
| 1970 A operator +(int x) {} |
| 1971 A operator -(int x) {} |
| 1972 A operator -() {} |
| 1973 } |
| 1974 |
| 1975 foo() => new A(); |
| 1976 |
| 1977 test() { |
| 1978 A a = new A(); |
| 1979 var c = foo(); |
| 1980 |
| 1981 ~a; |
| 1982 (/*info:DynamicInvoke*/~d); |
| 1983 |
| 1984 !/*severe:StaticTypeError*/a; |
| 1985 !/*info:DynamicCast*/d; |
| 1986 |
| 1987 -a; |
| 1988 (/*info:DynamicInvoke*/-d); |
| 1989 |
| 1990 ++a; |
| 1991 --a; |
| 1992 (/*info:DynamicInvoke*/++d); |
| 1993 (/*info:DynamicInvoke*/--d); |
| 1994 |
| 1995 a++; |
| 1996 a--; |
| 1997 (/*info:DynamicInvoke*/d++); |
| 1998 (/*info:DynamicInvoke*/d--); |
| 1999 }''' |
| 2000 })); |
| 2001 |
1927 test('binary and index operators', () { | 2002 test('binary and index operators', () { |
1928 testChecker({ | 2003 testChecker({ |
1929 '/main.dart': ''' | 2004 '/main.dart': ''' |
1930 class A { | 2005 class A { |
1931 A operator *(B b) {} | 2006 A operator *(B b) {} |
1932 A operator /(B b) {} | 2007 A operator /(B b) {} |
1933 A operator ~/(B b) {} | 2008 A operator ~/(B b) {} |
1934 A operator %(B b) {} | 2009 A operator %(B b) {} |
1935 A operator +(B b) {} | 2010 A operator +(B b) {} |
1936 A operator -(B b) {} | 2011 A operator -(B b) {} |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2957 '/main.dart': ''' | 3032 '/main.dart': ''' |
2958 import 'dart:foobar' show Baz; | 3033 import 'dart:foobar' show Baz; |
2959 main() { | 3034 main() { |
2960 print(Baz.quux); | 3035 print(Baz.quux); |
2961 }''' | 3036 }''' |
2962 }, | 3037 }, |
2963 customUrlMappings: { | 3038 customUrlMappings: { |
2964 'dart:foobar': '$testDirectory/checker/dart_foobar.dart' | 3039 'dart:foobar': '$testDirectory/checker/dart_foobar.dart' |
2965 })); | 3040 })); |
2966 } | 3041 } |
OLD | NEW |