| 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 /// Tests for type inference. | 5 /// Tests for type inference. |
| 6 library dev_compiler.test.inferred_type_test; | 6 library dev_compiler.test.inferred_type_test; |
| 7 | 7 |
| 8 import 'package:unittest/unittest.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'; |
| 11 | 11 |
| 12 import '../test_util.dart'; | |
| 13 | |
| 14 void main() { | 12 void main() { |
| 15 configureTest(); | |
| 16 | |
| 17 test('infer type on var', () { | 13 test('infer type on var', () { |
| 18 // Error also expected when declared type is `int`. | 14 // Error also expected when declared type is `int`. |
| 19 testChecker({ | 15 testChecker({ |
| 20 '/main.dart': ''' | 16 '/main.dart': ''' |
| 21 test1() { | 17 test1() { |
| 22 int x = 3; | 18 int x = 3; |
| 23 x = /*severe:StaticTypeError*/"hi"; | 19 x = /*severe:StaticTypeError*/"hi"; |
| 24 } | 20 } |
| 25 ''' | 21 ''' |
| 26 }); | 22 }); |
| 27 | 23 |
| 28 // If inferred type is `int`, error is also reported | 24 // If inferred type is `int`, error is also reported |
| 29 testChecker({ | 25 testChecker({ |
| 30 '/main.dart': ''' | 26 '/main.dart': ''' |
| 31 test2() { | 27 test2() { |
| 32 var x = 3; | 28 var x = 3; |
| 33 x = /*severe:StaticTypeError*/"hi"; | 29 x = /*severe:StaticTypeError*/"hi"; |
| 34 } | 30 } |
| 35 ''' | 31 ''' |
| 36 }); | 32 }); |
| 37 }); | 33 }); |
| 38 | 34 |
| 39 // Error when declared type is `int` and assigned null. | 35 test('Error when declared type is `int` and assigned null.', () { |
| 40 testChecker({ | 36 testChecker({ |
| 41 '/main.dart': ''' | 37 '/main.dart': ''' |
| 42 test1() { | 38 test1() { |
| 43 int x = 3; | 39 int x = 3; |
| 44 x = /*severe:StaticTypeError*/null; | 40 x = /*severe:StaticTypeError*/null; |
| 45 } | 41 } |
| 46 ''' | 42 ''' |
| 47 }, nonnullableTypes: <String>['int', 'double']); | 43 }, nonnullableTypes: <String>['int', 'double']); |
| 44 }); |
| 48 | 45 |
| 49 // Error when inferred type is `int` and assigned null. | 46 test('Error when inferred type is `int` and assigned null.', () { |
| 50 testChecker({ | 47 testChecker({ |
| 51 '/main.dart': ''' | 48 '/main.dart': ''' |
| 52 test1() { | 49 test1() { |
| 53 var x = 3; | 50 var x = 3; |
| 54 x = /*severe:StaticTypeError*/null; | 51 x = /*severe:StaticTypeError*/null; |
| 55 } | 52 } |
| 56 ''' | 53 ''' |
| 57 }, nonnullableTypes: <String>['int', 'double']); | 54 }, nonnullableTypes: <String>['int', 'double']); |
| 55 }); |
| 58 | 56 |
| 59 // No error when declared type is `num` and assigned null. | 57 test('No error when declared type is `num` and assigned null.', () { |
| 60 testChecker({ | 58 testChecker({ |
| 61 '/main.dart': ''' | 59 '/main.dart': ''' |
| 62 test1() { | 60 test1() { |
| 63 num x = 3; | 61 num x = 3; |
| 64 x = null; | 62 x = null; |
| 65 } | 63 } |
| 66 ''' | 64 ''' |
| 65 }); |
| 67 }); | 66 }); |
| 68 | 67 |
| 69 test('do not infer type on dynamic', () { | 68 test('do not infer type on dynamic', () { |
| 70 testChecker({ | 69 testChecker({ |
| 71 '/main.dart': ''' | 70 '/main.dart': ''' |
| 72 test() { | 71 test() { |
| 73 dynamic x = 3; | 72 dynamic x = 3; |
| 74 x = "hi"; | 73 x = "hi"; |
| 75 } | 74 } |
| 76 ''' | 75 ''' |
| (...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 Function2<int, int> l1 = /*info:InferredTypeClosure*/(x) => /*info:Dyn
amicInvoke should be pass*/x+1; | 1509 Function2<int, int> l1 = /*info:InferredTypeClosure*/(x) => /*info:Dyn
amicInvoke should be pass*/x+1; |
| 1511 Function2<int, String> l2 = /*info:InferredTypeClosure should be sever
e:StaticTypeError*/(x) => x; | 1510 Function2<int, String> l2 = /*info:InferredTypeClosure should be sever
e:StaticTypeError*/(x) => x; |
| 1512 Function2<int, String> l3 = /*info:InferredTypeClosure should be sever
e:StaticTypeError*/(x) => /*info:DynamicInvoke should be pass*/x.substring(3); | 1511 Function2<int, String> l3 = /*info:InferredTypeClosure should be sever
e:StaticTypeError*/(x) => /*info:DynamicInvoke should be pass*/x.substring(3); |
| 1513 Function2<String, String> l4 = /*info:InferredTypeClosure*/(x) => /*in
fo:DynamicInvoke should be pass*/x.substring(3); | 1512 Function2<String, String> l4 = /*info:InferredTypeClosure*/(x) => /*in
fo:DynamicInvoke should be pass*/x.substring(3); |
| 1514 } | 1513 } |
| 1515 } | 1514 } |
| 1516 ''' | 1515 ''' |
| 1517 }, inferDownwards: true, wrapClosures: false); | 1516 }, inferDownwards: true, wrapClosures: false); |
| 1518 }); | 1517 }); |
| 1519 } | 1518 } |
| OLD | NEW |