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

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

Issue 2231273002: fix #26120, sideways casts no longer supported (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix Created 4 years, 4 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 '../../../reflective_tests.dart'; 7 import '../../../reflective_tests.dart';
8 import 'strong_test_helper.dart'; 8 import 'strong_test_helper.dart';
9 9
10 void main() { 10 void main() {
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 Top f; 800 Top f;
801 f = top; 801 f = top;
802 f = left; 802 f = left;
803 f = right; 803 f = right;
804 f = bot; 804 f = bot;
805 } 805 }
806 { 806 {
807 Left f; 807 Left f;
808 f = /*error:STATIC_TYPE_ERROR*/top; 808 f = /*error:STATIC_TYPE_ERROR*/top;
809 f = left; 809 f = left;
810 f = /*error:STATIC_TYPE_ERROR*/right; 810 f = /*error:INVALID_ASSIGNMENT*/right;
811 f = bot; 811 f = bot;
812 } 812 }
813 { 813 {
814 Right f; 814 Right f;
815 f = /*error:STATIC_TYPE_ERROR*/top; 815 f = /*error:STATIC_TYPE_ERROR*/top;
816 f = /*error:STATIC_TYPE_ERROR*/left; 816 f = /*error:INVALID_ASSIGNMENT*/left;
817 f = right; 817 f = right;
818 f = bot; 818 f = bot;
819 } 819 }
820 { 820 {
821 Bot f; 821 Bot f;
822 f = /*error:STATIC_TYPE_ERROR*/top; 822 f = /*error:STATIC_TYPE_ERROR*/top;
823 f = /*error:STATIC_TYPE_ERROR*/left; 823 f = /*error:STATIC_TYPE_ERROR*/left;
824 f = /*error:STATIC_TYPE_ERROR*/right; 824 f = /*error:STATIC_TYPE_ERROR*/right;
825 f = bot; 825 f = bot;
826 } 826 }
(...skipping 19 matching lines...) Expand all
846 Top f; 846 Top f;
847 f = top; 847 f = top;
848 f = left; 848 f = left;
849 f = right; 849 f = right;
850 f = bot; 850 f = bot;
851 } 851 }
852 { 852 {
853 Left f; 853 Left f;
854 f = /*warning:DOWN_CAST_COMPOSITE*/top; 854 f = /*warning:DOWN_CAST_COMPOSITE*/top;
855 f = left; 855 f = left;
856 f = /*warning:DOWN_CAST_COMPOSITE*/right; 856 f = /*error:INVALID_ASSIGNMENT*/right;
857 f = bot; 857 f = bot;
858 } 858 }
859 { 859 {
860 Right f; 860 Right f;
861 f = /*warning:DOWN_CAST_COMPOSITE*/top; 861 f = /*warning:DOWN_CAST_COMPOSITE*/top;
862 f = /*warning:DOWN_CAST_COMPOSITE*/left; 862 f = /*error:INVALID_ASSIGNMENT*/left;
863 f = right; 863 f = right;
864 f = bot; 864 f = bot;
865 } 865 }
866 { 866 {
867 Bottom f; 867 Bottom f;
868 f = /*warning:DOWN_CAST_COMPOSITE*/top; 868 f = /*warning:DOWN_CAST_COMPOSITE*/top;
869 f = /*warning:DOWN_CAST_COMPOSITE*/left; 869 f = /*warning:DOWN_CAST_COMPOSITE*/left;
870 f = /*warning:DOWN_CAST_COMPOSITE*/right; 870 f = /*warning:DOWN_CAST_COMPOSITE*/right;
871 f = bot; 871 f = bot;
872 } 872 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 botA, 933 botA,
934 botTop 934 botTop
935 ); 935 );
936 } 936 }
937 { 937 {
938 ATop f; 938 ATop f;
939 f = topA; 939 f = topA;
940 f = topTop; 940 f = topTop;
941 f = aa; 941 f = aa;
942 f = aTop; 942 f = aTop;
943 f = /*warning:DOWN_CAST_COMPOSITE should be error:STATIC_TYPE_ERROR*/botA; 943 f = /*error:INVALID_ASSIGNMENT*/botA;
944 f = /*warning:DOWN_CAST_COMPOSITE*/botTop; 944 f = /*warning:DOWN_CAST_COMPOSITE*/botTop;
945 apply/*<ATop>*/( 945 apply/*<ATop>*/(
946 topA, 946 topA,
947 topTop, 947 topTop,
948 aa, 948 aa,
949 aTop, 949 aTop,
950 /*warning:DOWN_CAST_COMPOSITE should be error:STATIC_TYPE_ERROR*/botA, 950 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
951 /*warning:DOWN_CAST_COMPOSITE*/botTop 951 /*warning:DOWN_CAST_COMPOSITE*/botTop
952 ); 952 );
953 apply/*<ATop>*/( 953 apply/*<ATop>*/(
954 (dynamic x) => new A(), 954 (dynamic x) => new A(),
955 (dynamic x) => (x as Object), 955 (dynamic x) => (x as Object),
956 (A x) => x, 956 (A x) => x,
957 (A x) => null, 957 (A x) => null,
958 /*warning:DOWN_CAST_COMPOSITE should be error:STATIC_TYPE_ERROR*/botA, 958 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
959 /*warning:DOWN_CAST_COMPOSITE*/botTop 959 /*warning:DOWN_CAST_COMPOSITE*/botTop
960 ); 960 );
961 } 961 }
962 { 962 {
963 BotA f; 963 BotA f;
964 f = topA; 964 f = topA;
965 f = /*error:STATIC_TYPE_ERROR*/topTop; 965 f = /*error:INVALID_ASSIGNMENT*/topTop;
966 f = aa; 966 f = aa;
967 f = /*error:STATIC_TYPE_ERROR*/aTop; 967 f = /*error:INVALID_ASSIGNMENT*/aTop;
968 f = botA; 968 f = botA;
969 f = /*warning:DOWN_CAST_COMPOSITE*/botTop; 969 f = /*warning:DOWN_CAST_COMPOSITE*/botTop;
970 apply/*<BotA>*/( 970 apply/*<BotA>*/(
971 topA, 971 topA,
972 /*error:STATIC_TYPE_ERROR*/topTop, 972 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/topTop,
973 aa, 973 aa,
974 /*error:STATIC_TYPE_ERROR*/aTop, 974 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/aTop,
975 botA, 975 botA,
976 /*warning:DOWN_CAST_COMPOSITE*/botTop 976 /*warning:DOWN_CAST_COMPOSITE*/botTop
977 ); 977 );
978 apply/*<BotA>*/( 978 apply/*<BotA>*/(
979 (dynamic x) => new A(), 979 (dynamic x) => new A(),
980 /*error:STATIC_TYPE_ERROR*/(dynamic x) => (x as Object), 980 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(dynamic x) => (x as Object),
981 (A x) => x, 981 (A x) => x,
982 /*error:STATIC_TYPE_ERROR*/(A x) => (x as Object), 982 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(A x) => (x as Object),
983 botA, 983 botA,
984 /*warning:DOWN_CAST_COMPOSITE*/botTop 984 /*warning:DOWN_CAST_COMPOSITE*/botTop
985 ); 985 );
986 } 986 }
987 { 987 {
988 AA f; 988 AA f;
989 f = topA; 989 f = topA;
990 f = /*error:STATIC_TYPE_ERROR*/topTop; 990 f = /*error:INVALID_ASSIGNMENT*/topTop;
991 f = aa; 991 f = aa;
992 f = /*error:STATIC_TYPE_ERROR*/aTop; // known function 992 f = /*error:STATIC_TYPE_ERROR*/aTop; // known function
993 f = /*warning:DOWN_CAST_COMPOSITE*/botA; 993 f = /*warning:DOWN_CAST_COMPOSITE*/botA;
994 f = /*warning:DOWN_CAST_COMPOSITE*/botTop; 994 f = /*warning:DOWN_CAST_COMPOSITE*/botTop;
995 apply/*<AA>*/( 995 apply/*<AA>*/(
996 topA, 996 topA,
997 /*error:STATIC_TYPE_ERROR*/topTop, 997 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/topTop,
998 aa, 998 aa,
999 /*error:STATIC_TYPE_ERROR*/aTop, // known function 999 /*error:STATIC_TYPE_ERROR*/aTop, // known function
1000 /*warning:DOWN_CAST_COMPOSITE*/botA, 1000 /*warning:DOWN_CAST_COMPOSITE*/botA,
1001 /*warning:DOWN_CAST_COMPOSITE*/botTop 1001 /*warning:DOWN_CAST_COMPOSITE*/botTop
1002 ); 1002 );
1003 apply/*<AA>*/( 1003 apply/*<AA>*/(
1004 (dynamic x) => new A(), 1004 (dynamic x) => new A(),
1005 /*error:STATIC_TYPE_ERROR*/(dynamic x) => (x as Object), 1005 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(dynamic x) => (x as Object),
1006 (A x) => x, 1006 (A x) => x,
1007 /*error:STATIC_TYPE_ERROR*/(A x) => (x as Object), // known function 1007 /*error:STATIC_TYPE_ERROR*/(A x) => (x as Object), // known function
1008 /*warning:DOWN_CAST_COMPOSITE*/botA, 1008 /*warning:DOWN_CAST_COMPOSITE*/botA,
1009 /*warning:DOWN_CAST_COMPOSITE*/botTop 1009 /*warning:DOWN_CAST_COMPOSITE*/botTop
1010 ); 1010 );
1011 } 1011 }
1012 { 1012 {
1013 TopTop f; 1013 TopTop f;
1014 f = topA; 1014 f = topA;
1015 f = topTop; 1015 f = topTop;
1016 f = /*error:STATIC_TYPE_ERROR*/aa; 1016 f = /*error:INVALID_ASSIGNMENT*/aa;
1017 f = /*error:STATIC_TYPE_ERROR*/aTop; // known function 1017 f = /*error:STATIC_TYPE_ERROR*/aTop; // known function
1018 f = /*warning:DOWN_CAST_COMPOSITE should be error:STATIC_TYPE_ERROR*/botA; 1018 f = /*error:INVALID_ASSIGNMENT*/botA;
1019 f = /*warning:DOWN_CAST_COMPOSITE*/botTop; 1019 f = /*warning:DOWN_CAST_COMPOSITE*/botTop;
1020 apply/*<TopTop>*/( 1020 apply/*<TopTop>*/(
1021 topA, 1021 topA,
1022 topTop, 1022 topTop,
1023 /*error:STATIC_TYPE_ERROR*/aa, 1023 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/aa,
1024 /*error:STATIC_TYPE_ERROR*/aTop, // known function 1024 /*error:STATIC_TYPE_ERROR*/aTop, // known function
1025 /*warning:DOWN_CAST_COMPOSITE should be error:STATIC_TYPE_ERROR*/botA, 1025 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
1026 /*warning:DOWN_CAST_COMPOSITE*/botTop 1026 /*warning:DOWN_CAST_COMPOSITE*/botTop
1027 ); 1027 );
1028 apply/*<TopTop>*/( 1028 apply/*<TopTop>*/(
1029 (dynamic x) => new A(), 1029 (dynamic x) => new A(),
1030 (dynamic x) => (x as Object), 1030 (dynamic x) => (x as Object),
1031 /*error:STATIC_TYPE_ERROR*/(A x) => x, 1031 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(A x) => x,
1032 /*error:STATIC_TYPE_ERROR*/(A x) => (x as Object), // known function 1032 /*error:STATIC_TYPE_ERROR*/(A x) => (x as Object), // known function
1033 /*warning:DOWN_CAST_COMPOSITE should be error:STATIC_TYPE_ERROR*/botA, 1033 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
1034 /*warning:DOWN_CAST_COMPOSITE*/botTop 1034 /*warning:DOWN_CAST_COMPOSITE*/botTop
1035 ); 1035 );
1036 } 1036 }
1037 { 1037 {
1038 TopA f; 1038 TopA f;
1039 f = topA; 1039 f = topA;
1040 f = /*error:STATIC_TYPE_ERROR*/topTop; // known function 1040 f = /*error:STATIC_TYPE_ERROR*/topTop; // known function
1041 f = /*error:STATIC_TYPE_ERROR*/aa; // known function 1041 f = /*error:STATIC_TYPE_ERROR*/aa; // known function
1042 f = /*error:STATIC_TYPE_ERROR*/aTop; // known function 1042 f = /*error:STATIC_TYPE_ERROR*/aTop; // known function
1043 f = /*warning:DOWN_CAST_COMPOSITE*/botA; 1043 f = /*warning:DOWN_CAST_COMPOSITE*/botA;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 1134
1135 void main() { 1135 void main() {
1136 { 1136 {
1137 Function2<B, A> f; 1137 Function2<B, A> f;
1138 f = top; 1138 f = top;
1139 f = left; 1139 f = left;
1140 f = right; 1140 f = right;
1141 f = bot; 1141 f = bot;
1142 } 1142 }
1143 { 1143 {
1144 Function2<B, B> f; 1144 Function2<B, B> f; // left
1145 f = /*error:STATIC_TYPE_ERROR*/top; 1145 f = /*error:STATIC_TYPE_ERROR*/top;
1146 f = left; 1146 f = left;
1147 f = /*error:STATIC_TYPE_ERROR*/right; 1147 f = /*error:INVALID_ASSIGNMENT*/right;
1148 f = bot; 1148 f = bot;
1149 } 1149 }
1150 { 1150 {
1151 Function2<A, A> f; 1151 Function2<A, A> f; // right
1152 f = /*error:STATIC_TYPE_ERROR*/top; 1152 f = /*error:STATIC_TYPE_ERROR*/top;
1153 f = /*error:STATIC_TYPE_ERROR*/left; 1153 f = /*error:INVALID_ASSIGNMENT*/left;
1154 f = right; 1154 f = right;
1155 f = bot; 1155 f = bot;
1156 } 1156 }
1157 { 1157 {
1158 Function2<A, B> f; 1158 Function2<A, B> f;
1159 f = /*error:STATIC_TYPE_ERROR*/top; 1159 f = /*error:STATIC_TYPE_ERROR*/top;
1160 f = /*error:STATIC_TYPE_ERROR*/left; 1160 f = /*error:STATIC_TYPE_ERROR*/left;
1161 f = /*error:STATIC_TYPE_ERROR*/right; 1161 f = /*error:STATIC_TYPE_ERROR*/right;
1162 f = bot; 1162 f = bot;
1163 } 1163 }
(...skipping 15 matching lines...) Expand all
1179 Function2<A, A> right; 1179 Function2<A, A> right;
1180 Function2<A, B> bot; 1180 Function2<A, B> bot;
1181 1181
1182 top = right; 1182 top = right;
1183 top = bot; 1183 top = bot;
1184 top = top; 1184 top = top;
1185 top = left; 1185 top = left;
1186 1186
1187 left = /*warning:DOWN_CAST_COMPOSITE*/top; 1187 left = /*warning:DOWN_CAST_COMPOSITE*/top;
1188 left = left; 1188 left = left;
1189 left = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this? 1189 left = /*error:INVALID_ASSIGNMENT*/right;
1190 left = bot; 1190 left = bot;
1191 1191
1192 right = /*warning:DOWN_CAST_COMPOSITE*/top; 1192 right = /*info:INVALID_ASSIGNMENT,warning:DOWN_CAST_COMPOSITE*/top;
1193 right = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this? 1193 right = /*error:INVALID_ASSIGNMENT*/left;
1194 right = right; 1194 right = /*info:INVALID_ASSIGNMENT*/right;
Jennifer Messerly 2016/08/10 22:24:07 note this hint. Analyzer seems to track which type
Brian Wilkerson 2016/08/10 22:56:02 The hint is a result of type propagation, which wi
Jennifer Messerly 2016/08/11 00:51:19 oh nice!
1195 right = bot; 1195 right = bot;
1196 1196
1197 bot = /*warning:DOWN_CAST_COMPOSITE*/top; 1197 bot = /*warning:DOWN_CAST_COMPOSITE*/top;
1198 bot = /*warning:DOWN_CAST_COMPOSITE*/left; 1198 bot = /*warning:DOWN_CAST_COMPOSITE*/left;
1199 bot = /*warning:DOWN_CAST_COMPOSITE*/right; 1199 bot = /*warning:DOWN_CAST_COMPOSITE*/right;
1200 bot = bot; 1200 bot = bot;
1201 } 1201 }
1202 } 1202 }
1203 '''); 1203 ''');
1204 } 1204 }
(...skipping 19 matching lines...) Expand all
1224 Function2<AToB, BToA> f; // Top 1224 Function2<AToB, BToA> f; // Top
1225 f = top; 1225 f = top;
1226 f = left; 1226 f = left;
1227 f = right; 1227 f = right;
1228 f = bot; 1228 f = bot;
1229 } 1229 }
1230 { 1230 {
1231 Function2<AToB, AToB> f; // Left 1231 Function2<AToB, AToB> f; // Left
1232 f = /*error:STATIC_TYPE_ERROR*/top; 1232 f = /*error:STATIC_TYPE_ERROR*/top;
1233 f = left; 1233 f = left;
1234 f = /*error:STATIC_TYPE_ERROR*/right; 1234 f = /*error:INVALID_ASSIGNMENT*/right;
1235 f = bot; 1235 f = bot;
1236 } 1236 }
1237 { 1237 {
1238 Function2<BToA, BToA> f; // Right 1238 Function2<BToA, BToA> f; // Right
1239 f = /*error:STATIC_TYPE_ERROR*/top; 1239 f = /*error:STATIC_TYPE_ERROR*/top;
1240 f = /*error:STATIC_TYPE_ERROR*/left; 1240 f = /*error:INVALID_ASSIGNMENT*/left;
1241 f = right; 1241 f = right;
1242 f = bot; 1242 f = bot;
1243 } 1243 }
1244 { 1244 {
1245 Function2<BToA, AToB> f; // Bot 1245 Function2<BToA, AToB> f; // Bot
1246 f = bot; 1246 f = bot;
1247 f = /*error:STATIC_TYPE_ERROR*/left; 1247 f = /*error:STATIC_TYPE_ERROR*/left;
1248 f = /*error:STATIC_TYPE_ERROR*/top; 1248 f = /*error:STATIC_TYPE_ERROR*/top;
1249 f = /*error:STATIC_TYPE_ERROR*/left; 1249 f = /*error:STATIC_TYPE_ERROR*/right;
1250 } 1250 }
1251 } 1251 }
1252 '''); 1252 ''');
1253 } 1253 }
1254 1254
1255 void test_functionTypingAndSubtyping_higherOrderFunctionLiteral2() { 1255 void test_functionTypingAndSubtyping_higherOrderFunctionLiteral2() {
1256 checkFile(''' 1256 checkFile('''
1257 class A {} 1257 class A {}
1258 class B extends A {} 1258 class B extends A {}
1259 1259
(...skipping 13 matching lines...) Expand all
1273 Function2<AToB, BToA> f; // Top 1273 Function2<AToB, BToA> f; // Top
1274 f = top; 1274 f = top;
1275 f = left; 1275 f = left;
1276 f = right; 1276 f = right;
1277 f = bot; 1277 f = bot;
1278 } 1278 }
1279 { 1279 {
1280 Function2<AToB, AToB> f; // Left 1280 Function2<AToB, AToB> f; // Left
1281 f = /*error:STATIC_TYPE_ERROR*/top; 1281 f = /*error:STATIC_TYPE_ERROR*/top;
1282 f = left; 1282 f = left;
1283 f = /*error:STATIC_TYPE_ERROR*/right; 1283 f = /*error:INVALID_ASSIGNMENT*/right;
1284 f = bot; 1284 f = bot;
1285 } 1285 }
1286 { 1286 {
1287 Function2<BToA, BToA> f; // Right 1287 Function2<BToA, BToA> f; // Right
1288 f = /*error:STATIC_TYPE_ERROR*/top; 1288 f = /*error:STATIC_TYPE_ERROR*/top;
1289 f = /*error:STATIC_TYPE_ERROR*/left; 1289 f = /*error:INVALID_ASSIGNMENT*/left;
1290 f = right; 1290 f = right;
1291 f = bot; 1291 f = bot;
1292 } 1292 }
1293 { 1293 {
1294 Function2<BToA, AToB> f; // Bot 1294 Function2<BToA, AToB> f; // Bot
1295 f = bot; 1295 f = bot;
1296 f = /*error:STATIC_TYPE_ERROR*/left; 1296 f = /*error:STATIC_TYPE_ERROR*/left;
1297 f = /*error:STATIC_TYPE_ERROR*/top; 1297 f = /*error:STATIC_TYPE_ERROR*/top;
1298 f = /*error:STATIC_TYPE_ERROR*/left; 1298 f = /*error:STATIC_TYPE_ERROR*/right;
1299 } 1299 }
1300 } 1300 }
1301 '''); 1301 ''');
1302 } 1302 }
1303 1303
1304 void test_functionTypingAndSubtyping_higherOrderFunctionLiteral3() { 1304 void test_functionTypingAndSubtyping_higherOrderFunctionLiteral3() {
1305 checkFile(''' 1305 checkFile('''
1306 class A {} 1306 class A {}
1307 class B extends A {} 1307 class B extends A {}
1308 1308
(...skipping 13 matching lines...) Expand all
1322 Function2<AToB, BToA> f; // Top 1322 Function2<AToB, BToA> f; // Top
1323 f = top; 1323 f = top;
1324 f = left; 1324 f = left;
1325 f = right; 1325 f = right;
1326 f = bot; 1326 f = bot;
1327 } 1327 }
1328 { 1328 {
1329 Function2<AToB, AToB> f; // Left 1329 Function2<AToB, AToB> f; // Left
1330 f = /*error:STATIC_TYPE_ERROR*/top; 1330 f = /*error:STATIC_TYPE_ERROR*/top;
1331 f = left; 1331 f = left;
1332 f = /*error:STATIC_TYPE_ERROR*/right; 1332 f = /*error:INVALID_ASSIGNMENT*/right;
1333 f = bot; 1333 f = bot;
1334 } 1334 }
1335 { 1335 {
1336 Function2<BToA, BToA> f; // Right 1336 Function2<BToA, BToA> f; // Right
1337 f = /*error:STATIC_TYPE_ERROR*/top; 1337 f = /*error:STATIC_TYPE_ERROR*/top;
1338 f = /*error:STATIC_TYPE_ERROR*/left; 1338 f = /*error:INVALID_ASSIGNMENT*/left;
1339 f = right; 1339 f = right;
1340 f = bot; 1340 f = bot;
1341 } 1341 }
1342 { 1342 {
1343 Function2<BToA, AToB> f; // Bot 1343 Function2<BToA, AToB> f; // Bot
1344 f = bot; 1344 f = bot;
1345 f = /*error:STATIC_TYPE_ERROR*/left; 1345 f = /*error:STATIC_TYPE_ERROR*/left;
1346 f = /*error:STATIC_TYPE_ERROR*/top; 1346 f = /*error:STATIC_TYPE_ERROR*/top;
1347 f = /*error:STATIC_TYPE_ERROR*/left; 1347 f = /*error:STATIC_TYPE_ERROR*/right;
1348 } 1348 }
1349 } 1349 }
1350 '''); 1350 ''');
1351 } 1351 }
1352 1352
1353 void test_functionTypingAndSubtyping_higherOrderFunctionVariables() { 1353 void test_functionTypingAndSubtyping_higherOrderFunctionVariables() {
1354 checkFile(''' 1354 checkFile('''
1355 class A {} 1355 class A {}
1356 class B extends A {} 1356 class B extends A {}
1357 1357
1358 typedef T Function2<S, T>(S z); 1358 typedef T Function2<S, T>(S z);
1359 1359
1360 void main() { 1360 void main() {
1361 { 1361 {
1362 Function2<Function2<A, B>, Function2<B, A>> top; 1362 Function2<Function2<A, B>, Function2<B, A>> top;
1363 Function2<Function2<B, A>, Function2<B, A>> right; 1363 Function2<Function2<B, A>, Function2<B, A>> right;
1364 Function2<Function2<A, B>, Function2<A, B>> left; 1364 Function2<Function2<A, B>, Function2<A, B>> left;
1365 Function2<Function2<B, A>, Function2<A, B>> bot; 1365 Function2<Function2<B, A>, Function2<A, B>> bot;
1366 1366
1367 top = right; 1367 top = right;
1368 top = bot; 1368 top = bot;
1369 top = top; 1369 top = top;
1370 top = left; 1370 top = left;
1371 1371
1372 left = /*warning:DOWN_CAST_COMPOSITE*/top; 1372 left = /*warning:DOWN_CAST_COMPOSITE*/top;
1373 left = left; 1373 left = left;
1374 left = 1374 left =
1375 /*warning:DOWN_CAST_COMPOSITE should be error:STATIC_TYPE_ERROR*/right; 1375 /*error:INVALID_ASSIGNMENT*/right;
1376 left = bot; 1376 left = bot;
1377 1377
1378 right = /*warning:DOWN_CAST_COMPOSITE*/top; 1378 right = /*warning:DOWN_CAST_COMPOSITE*/top;
1379 right = 1379 right =
1380 /*warning:DOWN_CAST_COMPOSITE should be error:STATIC_TYPE_ERROR*/left; 1380 /*error:INVALID_ASSIGNMENT*/left;
1381 right = right; 1381 right = right;
1382 right = bot; 1382 right = bot;
1383 1383
1384 bot = /*warning:DOWN_CAST_COMPOSITE*/top; 1384 bot = /*warning:DOWN_CAST_COMPOSITE*/top;
1385 bot = /*warning:DOWN_CAST_COMPOSITE*/left; 1385 bot = /*warning:DOWN_CAST_COMPOSITE*/left;
1386 bot = /*warning:DOWN_CAST_COMPOSITE*/right; 1386 bot = /*warning:DOWN_CAST_COMPOSITE*/right;
1387 bot = bot; 1387 bot = bot;
1388 } 1388 }
1389 } 1389 }
1390 '''); 1390 ''');
(...skipping 19 matching lines...) Expand all
1410 Function2<B, A> f; 1410 Function2<B, A> f;
1411 f = c.top; 1411 f = c.top;
1412 f = c.left; 1412 f = c.left;
1413 f = c.right; 1413 f = c.right;
1414 f = c.bot; 1414 f = c.bot;
1415 } 1415 }
1416 { 1416 {
1417 Function2<B, B> f; 1417 Function2<B, B> f;
1418 f = /*warning:DOWN_CAST_COMPOSITE*/c.top; 1418 f = /*warning:DOWN_CAST_COMPOSITE*/c.top;
1419 f = c.left; 1419 f = c.left;
1420 f = /*warning:DOWN_CAST_COMPOSITE*/c.right; 1420 f = /*error:INVALID_ASSIGNMENT*/c.right;
1421 f = c.bot; 1421 f = c.bot;
1422 } 1422 }
1423 { 1423 {
1424 Function2<A, A> f; 1424 Function2<A, A> f;
1425 f = /*warning:DOWN_CAST_COMPOSITE*/c.top; 1425 f = /*warning:DOWN_CAST_COMPOSITE*/c.top;
1426 f = /*warning:DOWN_CAST_COMPOSITE*/c.left; 1426 f = /*error:INVALID_ASSIGNMENT*/c.left;
1427 f = c.right; 1427 f = c.right;
1428 f = c.bot; 1428 f = c.bot;
1429 } 1429 }
1430 { 1430 {
1431 Function2<A, B> f; 1431 Function2<A, B> f;
1432 f = /*warning:DOWN_CAST_COMPOSITE*/c.top; 1432 f = /*warning:DOWN_CAST_COMPOSITE*/c.top;
1433 f = /*warning:DOWN_CAST_COMPOSITE*/c.left; 1433 f = /*warning:DOWN_CAST_COMPOSITE*/c.left;
1434 f = /*warning:DOWN_CAST_COMPOSITE*/c.right; 1434 f = /*warning:DOWN_CAST_COMPOSITE*/c.right;
1435 f = c.bot; 1435 f = c.bot;
1436 } 1436 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 Top f; 1468 Top f;
1469 f = top; 1469 f = top;
1470 f = left; 1470 f = left;
1471 f = right; 1471 f = right;
1472 f = bot; 1472 f = bot;
1473 } 1473 }
1474 { 1474 {
1475 Left f; 1475 Left f;
1476 f = /*warning:DOWN_CAST_COMPOSITE*/top; 1476 f = /*warning:DOWN_CAST_COMPOSITE*/top;
1477 f = left; 1477 f = left;
1478 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this? 1478 f = /*error:INVALID_ASSIGNMENT*/right;
1479 f = bot; 1479 f = bot;
1480 } 1480 }
1481 { 1481 {
1482 Right f; 1482 Right f;
1483 f = /*warning:DOWN_CAST_COMPOSITE*/top; 1483 f = /*warning:DOWN_CAST_COMPOSITE*/top;
1484 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this? 1484 f = /*error:INVALID_ASSIGNMENT*/left;
1485 f = right; 1485 f = right;
1486 f = bot; 1486 f = bot;
1487 } 1487 }
1488 { 1488 {
1489 Bot f; 1489 Bot f;
1490 f = /*warning:DOWN_CAST_COMPOSITE*/top; 1490 f = /*warning:DOWN_CAST_COMPOSITE*/top;
1491 f = /*warning:DOWN_CAST_COMPOSITE*/left; 1491 f = /*warning:DOWN_CAST_COMPOSITE*/left;
1492 f = /*warning:DOWN_CAST_COMPOSITE*/right; 1492 f = /*warning:DOWN_CAST_COMPOSITE*/right;
1493 f = bot; 1493 f = bot;
1494 } 1494 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 num call(num x) => x; 1625 num call(num x) => x;
1626 } 1626 }
1627 int i2i(int x) => x; 1627 int i2i(int x) => x;
1628 num n2n(num x) => x; 1628 num n2n(num x) => x;
1629 void main() { 1629 void main() {
1630 { 1630 {
1631 I2I f; 1631 I2I f;
1632 f = new A(); 1632 f = new A();
1633 f = /*error:INVALID_ASSIGNMENT*/new B(); 1633 f = /*error:INVALID_ASSIGNMENT*/new B();
1634 f = i2i; 1634 f = i2i;
1635 f = /*error:STATIC_TYPE_ERROR*/n2n; 1635 f = /*error:INVALID_ASSIGNMENT*/n2n;
1636 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object; 1636 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object;
1637 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function; 1637 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function;
1638 } 1638 }
1639 { 1639 {
1640 N2N f; 1640 N2N f;
1641 f = /*error:INVALID_ASSIGNMENT*/new A(); 1641 f = /*error:INVALID_ASSIGNMENT*/new A();
1642 f = new B(); 1642 f = new B();
1643 f = /*error:STATIC_TYPE_ERROR*/i2i; 1643 f = /*error:INVALID_ASSIGNMENT*/i2i;
1644 f = n2n; 1644 f = n2n;
1645 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object; 1645 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object;
1646 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function; 1646 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function;
1647 } 1647 }
1648 { 1648 {
1649 A f; 1649 A f;
1650 f = new A(); 1650 f = new A();
1651 f = /*error:INVALID_ASSIGNMENT*/new B(); 1651 f = /*error:INVALID_ASSIGNMENT*/new B();
1652 f = /*error:INVALID_ASSIGNMENT*/i2i; 1652 f = /*error:INVALID_ASSIGNMENT*/i2i;
1653 f = /*error:INVALID_ASSIGNMENT*/n2n; 1653 f = /*error:INVALID_ASSIGNMENT*/n2n;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 Function2<B, A> f; 1695 Function2<B, A> f;
1696 f = C.top; 1696 f = C.top;
1697 f = C.left; 1697 f = C.left;
1698 f = C.right; 1698 f = C.right;
1699 f = C.bot; 1699 f = C.bot;
1700 } 1700 }
1701 { 1701 {
1702 Function2<B, B> f; 1702 Function2<B, B> f;
1703 f = /*error:STATIC_TYPE_ERROR*/C.top; 1703 f = /*error:STATIC_TYPE_ERROR*/C.top;
1704 f = C.left; 1704 f = C.left;
1705 f = /*error:STATIC_TYPE_ERROR*/C.right; 1705 f = /*error:INVALID_ASSIGNMENT*/C.right;
1706 f = C.bot; 1706 f = C.bot;
1707 } 1707 }
1708 { 1708 {
1709 Function2<A, A> f; 1709 Function2<A, A> f;
1710 f = /*error:STATIC_TYPE_ERROR*/C.top; 1710 f = /*error:STATIC_TYPE_ERROR*/C.top;
1711 f = /*error:STATIC_TYPE_ERROR*/C.left; 1711 f = /*error:INVALID_ASSIGNMENT*/C.left;
1712 f = C.right; 1712 f = C.right;
1713 f = C.bot; 1713 f = C.bot;
1714 } 1714 }
1715 { 1715 {
1716 Function2<A, B> f; 1716 Function2<A, B> f;
1717 f = /*error:STATIC_TYPE_ERROR*/C.top; 1717 f = /*error:STATIC_TYPE_ERROR*/C.top;
1718 f = /*error:STATIC_TYPE_ERROR*/C.left; 1718 f = /*error:STATIC_TYPE_ERROR*/C.left;
1719 f = /*error:STATIC_TYPE_ERROR*/C.right; 1719 f = /*error:STATIC_TYPE_ERROR*/C.right;
1720 f = C.bot; 1720 f = C.bot;
1721 } 1721 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 local = /*error:INVALID_ASSIGNMENT*/nonGenericFn; 1755 local = /*error:INVALID_ASSIGNMENT*/nonGenericFn;
1756 } 1756 }
1757 } 1757 }
1758 '''); 1758 ''');
1759 } 1759 }
1760 1760
1761 void test_functionTypingAndSubtyping_uninferredClosure() { 1761 void test_functionTypingAndSubtyping_uninferredClosure() {
1762 checkFile(''' 1762 checkFile('''
1763 typedef num Num2Num(num x); 1763 typedef num Num2Num(num x);
1764 void main() { 1764 void main() {
1765 Num2Num g = /*info:INFERRED_TYPE_CLOSURE,error:STATIC_TYPE_ERROR*/(int x) { re turn x; }; 1765 Num2Num g = /*info:INFERRED_TYPE_CLOSURE,error:INVALID_ASSIGNMENT*/(int x) { r eturn x; };
1766 print(g(42)); 1766 print(g(42));
1767 } 1767 }
1768 '''); 1768 ''');
1769 } 1769 }
1770 1770
1771 void test_functionTypingAndSubtyping_void() { 1771 void test_functionTypingAndSubtyping_void() {
1772 checkFile(''' 1772 checkFile('''
1773 class A { 1773 class A {
1774 void bar() => null; 1774 void bar() => null;
1775 void foo() => bar(); // allowed 1775 void foo() => bar(); // allowed
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 { 3116 {
3117 lOfOs = mOfDs; 3117 lOfOs = mOfDs;
3118 lOfOs = mOfOs; 3118 lOfOs = mOfOs;
3119 lOfOs = mOfAs; 3119 lOfOs = mOfAs;
3120 lOfOs = lOfDs; 3120 lOfOs = lOfDs;
3121 lOfOs = lOfOs; 3121 lOfOs = lOfOs;
3122 lOfOs = lOfAs; 3122 lOfOs = lOfAs;
3123 lOfOs = new L<Object>(); // Reset type propagation. 3123 lOfOs = new L<Object>(); // Reset type propagation.
3124 } 3124 }
3125 { 3125 {
3126 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs; 3126 lOfAs = /*error:INVALID_ASSIGNMENT*/mOfDs;
3127 lOfAs = /*error:INVALID_ASSIGNMENT*/mOfOs; 3127 lOfAs = /*error:INVALID_ASSIGNMENT*/mOfOs;
3128 lOfAs = mOfAs; 3128 lOfAs = mOfAs;
3129 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs; 3129 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs;
3130 lOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; 3130 lOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
3131 lOfAs = lOfAs; 3131 lOfAs = lOfAs;
3132 lOfAs = new L<A>(); // Reset type propagation. 3132 lOfAs = new L<A>(); // Reset type propagation.
3133 } 3133 }
3134 { 3134 {
3135 mOfDs = mOfDs; 3135 mOfDs = mOfDs;
3136 mOfDs = mOfOs; 3136 mOfDs = mOfOs;
3137 mOfDs = mOfAs; 3137 mOfDs = mOfAs;
3138 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfDs; 3138 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfDs;
3139 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; 3139 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
3140 mOfDs = /*warning:DOWN_CAST_COMPOSITE*/lOfAs; 3140 mOfDs = /*error:INVALID_ASSIGNMENT*/lOfAs;
3141 mOfDs = new M(); // Reset type propagation. 3141 mOfDs = new M(); // Reset type propagation.
3142 } 3142 }
3143 { 3143 {
3144 mOfOs = mOfDs; 3144 mOfOs = mOfDs;
3145 mOfOs = mOfOs; 3145 mOfOs = mOfOs;
3146 mOfOs = mOfAs; 3146 mOfOs = mOfAs;
3147 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfDs; 3147 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfDs;
3148 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; 3148 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
3149 mOfOs = /*error:INVALID_ASSIGNMENT*/lOfAs; 3149 mOfOs = /*error:INVALID_ASSIGNMENT*/lOfAs;
3150 mOfOs = new M<Object>(); // Reset type propagation. 3150 mOfOs = new M<Object>(); // Reset type propagation.
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
3717 // Regression test for https://github.com/dart-lang/sdk/issues/25069 3717 // Regression test for https://github.com/dart-lang/sdk/issues/25069
3718 checkFile(''' 3718 checkFile('''
3719 typedef int Foo(); 3719 typedef int Foo();
3720 void foo() {} 3720 void foo() {}
3721 void main () { 3721 void main () {
3722 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); 3722 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo();
3723 } 3723 }
3724 '''); 3724 ''');
3725 } 3725 }
3726 } 3726 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698