comparison src/vim9compile.c @ 19467:f41e46f02c8c v8.2.0291

patch 8.2.0291: Vim9: assigning [] to list<string> doesn't work Commit: https://github.com/vim/vim/commit/436472f5e0328dc4a635b1c344c04a62d64132ea Author: Bram Moolenaar <Bram@vim.org> Date: Thu Feb 20 22:54:43 2020 +0100 patch 8.2.0291: Vim9: assigning [] to list<string> doesn't work Problem: Vim9: assigning [] to list<string> doesn't work. Solution: Use void for empty list and dict. (Ken Takata, closes https://github.com/vim/vim/issues/5669)
author Bram Moolenaar <Bram@vim.org>
date Thu, 20 Feb 2020 23:00:05 +0100
parents 08ef11a81daa
children b09afbebffee
comparison
equal deleted inserted replaced
19466:f4820960d7e8 19467:f41e46f02c8c
209 type_T *type; 209 type_T *type;
210 210
211 // recognize commonly used types 211 // recognize commonly used types
212 if (member_type->tt_type == VAR_UNKNOWN) 212 if (member_type->tt_type == VAR_UNKNOWN)
213 return &t_list_any; 213 return &t_list_any;
214 if (member_type->tt_type == VAR_VOID)
215 return &t_list_empty;
214 if (member_type->tt_type == VAR_NUMBER) 216 if (member_type->tt_type == VAR_NUMBER)
215 return &t_list_number; 217 return &t_list_number;
216 if (member_type->tt_type == VAR_STRING) 218 if (member_type->tt_type == VAR_STRING)
217 return &t_list_string; 219 return &t_list_string;
218 220
232 type_T *type; 234 type_T *type;
233 235
234 // recognize commonly used types 236 // recognize commonly used types
235 if (member_type->tt_type == VAR_UNKNOWN) 237 if (member_type->tt_type == VAR_UNKNOWN)
236 return &t_dict_any; 238 return &t_dict_any;
239 if (member_type->tt_type == VAR_VOID)
240 return &t_dict_empty;
237 if (member_type->tt_type == VAR_NUMBER) 241 if (member_type->tt_type == VAR_NUMBER)
238 return &t_dict_number; 242 return &t_dict_number;
239 if (member_type->tt_type == VAR_STRING) 243 if (member_type->tt_type == VAR_STRING)
240 return &t_dict_string; 244 return &t_dict_string;
241 245
811 isn->isn_arg.number = count; 815 isn->isn_arg.number = count;
812 816
813 // drop the value types 817 // drop the value types
814 stack->ga_len -= count; 818 stack->ga_len -= count;
815 819
816 // use the first value type for the list member type 820 // Use the first value type for the list member type. Use "void" for an
821 // empty list.
817 if (count > 0) 822 if (count > 0)
818 member = ((type_T **)stack->ga_data)[stack->ga_len]; 823 member = ((type_T **)stack->ga_data)[stack->ga_len];
819 else 824 else
820 member = &t_any; 825 member = &t_void;
821 type = get_list_type(member, type_list); 826 type = get_list_type(member, type_list);
822 827
823 // add the list type to the type stack 828 // add the list type to the type stack
824 if (ga_grow(stack, 1) == FAIL) 829 if (ga_grow(stack, 1) == FAIL)
825 return FAIL; 830 return FAIL;
846 isn->isn_arg.number = count; 851 isn->isn_arg.number = count;
847 852
848 // drop the key and value types 853 // drop the key and value types
849 stack->ga_len -= 2 * count; 854 stack->ga_len -= 2 * count;
850 855
851 // use the first value type for the list member type 856 // Use the first value type for the list member type. Use "void" for an
857 // empty dict.
852 if (count > 0) 858 if (count > 0)
853 member = ((type_T **)stack->ga_data)[stack->ga_len + 1]; 859 member = ((type_T **)stack->ga_data)[stack->ga_len + 1];
854 else 860 else
855 member = &t_any; 861 member = &t_void;
856 type = get_dict_type(member, type_list); 862 type = get_dict_type(member, type_list);
857 863
858 // add the dict type to the type stack 864 // add the dict type to the type stack
859 if (ga_grow(stack, 1) == FAIL) 865 if (ga_grow(stack, 1) == FAIL)
860 return FAIL; 866 return FAIL;
1852 type_mismatch(expected, actual); 1858 type_mismatch(expected, actual);
1853 return FAIL; 1859 return FAIL;
1854 } 1860 }
1855 if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST) 1861 if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST)
1856 { 1862 {
1857 int ret = check_type(expected->tt_member, actual->tt_member, 1863 int ret;
1858 FALSE); 1864
1865 // void is used for an empty list or dict
1866 if (actual->tt_member == &t_void)
1867 ret = OK;
1868 else
1869 ret = check_type(expected->tt_member, actual->tt_member, FALSE);
1859 if (ret == FAIL && give_msg) 1870 if (ret == FAIL && give_msg)
1860 type_mismatch(expected, actual); 1871 type_mismatch(expected, actual);
1861 return ret; 1872 return ret;
1862 } 1873 }
1863 } 1874 }
1871 * - return FAIL. 1882 * - return FAIL.
1872 */ 1883 */
1873 static int 1884 static int
1874 need_type(type_T *actual, type_T *expected, int offset, cctx_T *cctx) 1885 need_type(type_T *actual, type_T *expected, int offset, cctx_T *cctx)
1875 { 1886 {
1876 if (equal_type(actual, expected) || expected->tt_type == VAR_UNKNOWN) 1887 if (check_type(expected, actual, FALSE))
1877 return OK; 1888 return OK;
1878 if (actual->tt_type != VAR_UNKNOWN) 1889 if (actual->tt_type != VAR_UNKNOWN)
1879 { 1890 {
1880 type_mismatch(expected, actual); 1891 type_mismatch(expected, actual);
1881 return FAIL; 1892 return FAIL;