comparison src/evalfunc.c @ 27551:845e518cda11 v8.2.4302

patch 8.2.4302: Vim9: return type of getline() is too strict Commit: https://github.com/vim/vim/commit/82e46e5d31ba1ca8d4e322acdacdd90ab80705d9 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 5 18:12:34 2022 +0000 patch 8.2.4302: Vim9: return type of getline() is too strict Problem: Vim9: return type of getline() is too strict. Solution: Make the declared type list<any>. Also do this for other functions returning a list of a specific type.
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Feb 2022 19:15:03 +0100
parents 4f1c67a5f446
children 829aec0d0387
comparison
equal deleted inserted replaced
27550:eabeeeee4902 27551:845e518cda11
1048 return &t_list_any; 1048 return &t_list_any;
1049 } 1049 }
1050 static type_T * 1050 static type_T *
1051 ret_list_number(int argcount UNUSED, 1051 ret_list_number(int argcount UNUSED,
1052 type2_T *argtypes UNUSED, 1052 type2_T *argtypes UNUSED,
1053 type_T **decl_type UNUSED)
1054 {
1055 return &t_list_number;
1056 }
1057 static type_T *
1058 ret_range(int argcount UNUSED,
1059 type2_T *argtypes UNUSED,
1060 type_T **decl_type) 1053 type_T **decl_type)
1061 { 1054 {
1062 // returning a list<number>, but it's not declared as such
1063 *decl_type = &t_list_any; 1055 *decl_type = &t_list_any;
1064 return &t_list_number; 1056 return &t_list_number;
1065 } 1057 }
1066 static type_T * 1058 static type_T *
1067 ret_list_string(int argcount UNUSED, 1059 ret_list_string(int argcount UNUSED,
1068 type2_T *argtypes UNUSED, 1060 type2_T *argtypes UNUSED,
1069 type_T **decl_type UNUSED) 1061 type_T **decl_type)
1070 { 1062 {
1063 *decl_type = &t_list_any;
1071 return &t_list_string; 1064 return &t_list_string;
1072 } 1065 }
1073 static type_T * 1066 static type_T *
1074 ret_list_dict_any(int argcount UNUSED, 1067 ret_list_dict_any(int argcount UNUSED,
1075 type2_T *argtypes UNUSED, 1068 type2_T *argtypes UNUSED,
1076 type_T **decl_type UNUSED) 1069 type_T **decl_type)
1077 { 1070 {
1071 *decl_type = &t_list_any;
1078 return &t_list_dict_any; 1072 return &t_list_dict_any;
1079 } 1073 }
1080 static type_T * 1074 static type_T *
1081 ret_list_items(int argcount UNUSED, 1075 ret_list_items(int argcount UNUSED,
1082 type2_T *argtypes UNUSED, 1076 type2_T *argtypes UNUSED,
1083 type_T **decl_type UNUSED) 1077 type_T **decl_type)
1084 { 1078 {
1079 *decl_type = &t_list_any;
1085 return &t_list_list_any; 1080 return &t_list_list_any;
1086 } 1081 }
1087 1082
1088 static type_T * 1083 static type_T *
1089 ret_list_string_items(int argcount UNUSED, 1084 ret_list_string_items(int argcount UNUSED,
1090 type2_T *argtypes UNUSED, 1085 type2_T *argtypes UNUSED,
1091 type_T **decl_type UNUSED) 1086 type_T **decl_type)
1092 { 1087 {
1088 *decl_type = &t_list_any;
1093 return &t_list_list_string; 1089 return &t_list_list_string;
1094 } 1090 }
1095 static type_T * 1091 static type_T *
1096 ret_dict_any(int argcount UNUSED, 1092 ret_dict_any(int argcount UNUSED,
1097 type2_T *argtypes UNUSED, 1093 type2_T *argtypes UNUSED,
1100 return &t_dict_any; 1096 return &t_dict_any;
1101 } 1097 }
1102 static type_T * 1098 static type_T *
1103 ret_job_info(int argcount, 1099 ret_job_info(int argcount,
1104 type2_T *argtypes UNUSED, 1100 type2_T *argtypes UNUSED,
1105 type_T **decl_type UNUSED) 1101 type_T **decl_type)
1106 { 1102 {
1107 if (argcount == 0) 1103 if (argcount == 0)
1104 {
1105 *decl_type = &t_list_any;
1108 return &t_list_job; 1106 return &t_list_job;
1107 }
1109 return &t_dict_any; 1108 return &t_dict_any;
1110 } 1109 }
1111 static type_T * 1110 static type_T *
1112 ret_dict_number(int argcount UNUSED, 1111 ret_dict_number(int argcount UNUSED,
1113 type2_T *argtypes UNUSED, 1112 type2_T *argtypes UNUSED,
1250 static type_T * 1249 static type_T *
1251 ret_getline(int argcount, 1250 ret_getline(int argcount,
1252 type2_T *argtypes UNUSED, 1251 type2_T *argtypes UNUSED,
1253 type_T **decl_type UNUSED) 1252 type_T **decl_type UNUSED)
1254 { 1253 {
1255 return argcount == 1 ? &t_string : &t_list_string; 1254 if (argcount == 1)
1255 return &t_string;
1256 *decl_type = &t_list_any;
1257 return &t_list_string;
1256 } 1258 }
1257 // for finddir() 1259 // for finddir()
1258 static type_T * 1260 static type_T *
1259 ret_finddir(int argcount, 1261 ret_finddir(int argcount,
1260 type2_T *argtypes UNUSED, 1262 type2_T *argtypes UNUSED,
1271 * one. 1273 * one.
1272 */ 1274 */
1273 static type_T * 1275 static type_T *
1274 ret_list_or_dict_0(int argcount, 1276 ret_list_or_dict_0(int argcount,
1275 type2_T *argtypes UNUSED, 1277 type2_T *argtypes UNUSED,
1276 type_T **decl_type UNUSED) 1278 type_T **decl_type)
1277 { 1279 {
1278 if (argcount > 0) 1280 if (argcount > 0)
1279 return &t_dict_any; 1281 return &t_dict_any;
1282 *decl_type = &t_list_any;
1280 return &t_list_dict_any; 1283 return &t_list_dict_any;
1281 } 1284 }
1282 1285
1283 /* 1286 /*
1284 * Used for getloclist(): returns list if there is one argument, dict if there 1287 * Used for getloclist(): returns list if there is one argument, dict if there
1285 * are two. 1288 * are two.
1286 */ 1289 */
1287 static type_T * 1290 static type_T *
1288 ret_list_or_dict_1(int argcount, 1291 ret_list_or_dict_1(int argcount,
1289 type2_T *argtypes UNUSED, 1292 type2_T *argtypes UNUSED,
1290 type_T **decl_type UNUSED) 1293 type_T **decl_type)
1291 { 1294 {
1292 if (argcount > 1) 1295 if (argcount > 1)
1293 return &t_dict_any; 1296 return &t_dict_any;
1297 *decl_type = &t_list_any;
1294 return &t_list_dict_any; 1298 return &t_list_dict_any;
1295 } 1299 }
1296 1300
1297 static type_T * 1301 static type_T *
1298 ret_argv(int argcount, 1302 ret_argv(int argcount,
1299 type2_T *argtypes UNUSED, 1303 type2_T *argtypes UNUSED,
1300 type_T **decl_type UNUSED) 1304 type_T **decl_type)
1301 { 1305 {
1302 // argv() returns list of strings 1306 // argv() returns list of strings
1303 if (argcount == 0) 1307 if (argcount == 0)
1308 {
1309 *decl_type = &t_list_any;
1304 return &t_list_string; 1310 return &t_list_string;
1311 }
1305 1312
1306 // argv(0) returns a string, but argv(-1] returns a list 1313 // argv(0) returns a string, but argv(-1] returns a list
1307 return &t_any; 1314 return &t_any;
1308 } 1315 }
1309 1316
1329 } 1336 }
1330 1337
1331 static type_T * 1338 static type_T *
1332 ret_getreg(int argcount, 1339 ret_getreg(int argcount,
1333 type2_T *argtypes UNUSED, 1340 type2_T *argtypes UNUSED,
1334 type_T **decl_type UNUSED) 1341 type_T **decl_type)
1335 { 1342 {
1336 // Assume that if the third argument is passed it's non-zero 1343 // Assume that if the third argument is passed it's non-zero
1337 if (argcount == 3) 1344 if (argcount == 3)
1345 {
1346 *decl_type = &t_list_any;
1338 return &t_list_string; 1347 return &t_list_string;
1348 }
1339 return &t_string; 1349 return &t_string;
1340 } 1350 }
1341 1351
1342 static type_T * 1352 static type_T *
1343 ret_maparg(int argcount, 1353 ret_maparg(int argcount,
1747 ret_string, f_getcmdwintype}, 1757 ret_string, f_getcmdwintype},
1748 {"getcompletion", 2, 3, FEARG_1, arg3_string_string_bool, 1758 {"getcompletion", 2, 3, FEARG_1, arg3_string_string_bool,
1749 ret_list_string, f_getcompletion}, 1759 ret_list_string, f_getcompletion},
1750 {"getcurpos", 0, 1, FEARG_1, arg1_number, 1760 {"getcurpos", 0, 1, FEARG_1, arg1_number,
1751 ret_list_number, f_getcurpos}, 1761 ret_list_number, f_getcurpos},
1752 {"getcursorcharpos", 0, 1, FEARG_1, arg1_number, 1762 {"getcursorcharpos", 0, 1, FEARG_1, arg1_number,
1753 ret_list_number, f_getcursorcharpos}, 1763 ret_list_number, f_getcursorcharpos},
1754 {"getcwd", 0, 2, FEARG_1, arg2_number, 1764 {"getcwd", 0, 2, FEARG_1, arg2_number,
1755 ret_string, f_getcwd}, 1765 ret_string, f_getcwd},
1756 {"getenv", 1, 1, FEARG_1, arg1_string, 1766 {"getenv", 1, 1, FEARG_1, arg1_string,
1757 ret_any, f_getenv}, 1767 ret_any, f_getenv},
2122 #endif 2132 #endif
2123 }, 2133 },
2124 {"rand", 0, 1, FEARG_1, arg1_list_number, 2134 {"rand", 0, 1, FEARG_1, arg1_list_number,
2125 ret_number, f_rand}, 2135 ret_number, f_rand},
2126 {"range", 1, 3, FEARG_1, arg3_number, 2136 {"range", 1, 3, FEARG_1, arg3_number,
2127 ret_range, f_range}, 2137 ret_list_number, f_range},
2128 {"readblob", 1, 1, FEARG_1, arg1_string, 2138 {"readblob", 1, 1, FEARG_1, arg1_string,
2129 ret_blob, f_readblob}, 2139 ret_blob, f_readblob},
2130 {"readdir", 1, 3, FEARG_1, arg3_string_any_dict, 2140 {"readdir", 1, 3, FEARG_1, arg3_string_any_dict,
2131 ret_list_string, f_readdir}, 2141 ret_list_string, f_readdir},
2132 {"readdirex", 1, 3, FEARG_1, arg3_string_any_dict, 2142 {"readdirex", 1, 3, FEARG_1, arg3_string_any_dict,