diff src/vim9compile.c @ 21301:60011b87aae1 v8.2.1201

patch 8.2.1201: Vim9: crash when passing number as dict key Commit: https://github.com/vim/vim/commit/f1a2368d81fc3f70dfcf7d577957185da6ccf0b6 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 13 18:55:48 2020 +0200 patch 8.2.1201: Vim9: crash when passing number as dict key Problem: Vim9: crash when passing number as dict key. Solution: Check key type to be string. (closes https://github.com/vim/vim/issues/6449)
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Jul 2020 19:00:04 +0200
parents 13b1567ae0c6
children af3663df42bf
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3212,6 +3212,7 @@ compile_lambda_call(char_u **arg, cctx_T
 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;
@@ -3254,10 +3255,16 @@ compile_dict(char_u **arg, cctx_T *cctx,
 
 	    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.