assert_equal(6, res)
enddef
+def Wrong_dict_key_type(items: list<number>): list<number>
+ return filter(items, {_, val -> get({val: 1}, 'x')})
+enddef
+
+def Test_wrong_dict_key_type()
+ assert_fails('Wrong_dict_key_type([1, 2, 3])', 'E1029:')
+enddef
+
def Line_continuation_in_def(dir: string = ''): string
let path: string = empty(dir)
\ ? 'empty'
compile_dict(char_u **arg, cctx_T *cctx, int literal)
{
garray_T *instr = &cctx->ctx_instr;
+ garray_T *stack = &cctx->ctx_type_stack;
int count = 0;
dict_T *d = dict_alloc();
dictitem_T *item;
if (compile_expr0(arg, cctx) == FAIL)
return FAIL;
- // TODO: check type is string
isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
if (isn->isn_type == ISN_PUSHS)
key = isn->isn_arg.string;
+ else
+ {
+ type_T *keytype = ((type_T **)stack->ga_data)
+ [stack->ga_len - 1];
+ if (need_type(keytype, &t_string, -1, cctx, FALSE) == FAIL)
+ return FAIL;
+ }
}
// Check for duplicate keys, if using string keys.