| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 engine.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 final int y; | 906 final int y; |
| 907 } | 907 } |
| 908 var v = const A('foo');'''); | 908 var v = const A('foo');'''); |
| 909 resolve(source); | 909 resolve(source); |
| 910 assertErrors(source, [ | 910 assertErrors(source, [ |
| 911 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH | 911 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH |
| 912 ]); | 912 ]); |
| 913 verify([source]); | 913 verify([source]); |
| 914 } | 914 } |
| 915 | 915 |
| 916 void test_fieldTypeMismatch_generic() { |
| 917 Source source = addSource(r''' |
| 918 class C<T> { |
| 919 final T x = y; |
| 920 const C(); |
| 921 } |
| 922 const y = 1; |
| 923 var v = const C<String>(); |
| 924 '''); |
| 925 resolve(source); |
| 926 assertErrors(source, [ |
| 927 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, |
| 928 HintCode.INVALID_ASSIGNMENT |
| 929 ]); |
| 930 verify([source]); |
| 931 } |
| 932 |
| 916 void test_fieldTypeMismatch_unresolved() { | 933 void test_fieldTypeMismatch_unresolved() { |
| 917 Source source = addSource(r''' | 934 Source source = addSource(r''' |
| 918 class A { | 935 class A { |
| 919 const A(x) : y = x; | 936 const A(x) : y = x; |
| 920 final Unresolved y; | 937 final Unresolved y; |
| 921 } | 938 } |
| 922 var v = const A('foo');'''); | 939 var v = const A('foo');'''); |
| 923 resolve(source); | 940 resolve(source); |
| 924 assertErrors(source, [ | 941 assertErrors(source, [ |
| 925 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, | 942 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, |
| 926 StaticWarningCode.UNDEFINED_CLASS | 943 StaticWarningCode.UNDEFINED_CLASS |
| 927 ]); | 944 ]); |
| 928 verify([source]); | 945 verify([source]); |
| 929 } | 946 } |
| 930 | 947 |
| 948 void test_fieldTypeOk_generic() { |
| 949 Source source = addSource(r''' |
| 950 class C<T> { |
| 951 final T x = y; |
| 952 const C(); |
| 953 } |
| 954 const y = 1; |
| 955 var v = const C<int>(); |
| 956 '''); |
| 957 resolve(source); |
| 958 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 959 verify([source]); |
| 960 } |
| 961 |
| 931 void test_fieldTypeOk_null() { | 962 void test_fieldTypeOk_null() { |
| 932 Source source = addSource(r''' | 963 Source source = addSource(r''' |
| 933 class A { | 964 class A { |
| 934 const A(x) : y = x; | 965 const A(x) : y = x; |
| 935 final int y; | 966 final int y; |
| 936 } | 967 } |
| 937 var v = const A(null);'''); | 968 var v = const A(null);'''); |
| 938 resolve(source); | 969 resolve(source); |
| 939 assertNoErrors(source); | 970 assertNoErrors(source); |
| 940 verify([source]); | 971 verify([source]); |
| (...skipping 12816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13757 // check propagated type | 13788 // check propagated type |
| 13758 FunctionType propagatedType = node.propagatedType as FunctionType; | 13789 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 13759 expect(propagatedType.returnType, test.typeProvider.stringType); | 13790 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 13760 } on AnalysisException catch (e, stackTrace) { | 13791 } on AnalysisException catch (e, stackTrace) { |
| 13761 thrownException[0] = new CaughtException(e, stackTrace); | 13792 thrownException[0] = new CaughtException(e, stackTrace); |
| 13762 } | 13793 } |
| 13763 } | 13794 } |
| 13764 return null; | 13795 return null; |
| 13765 } | 13796 } |
| 13766 } | 13797 } |
| OLD | NEW |