patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Problem: Vim9: always converting to string for ".." leads to mistakes.
Solution: Only automatically convert simple types.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 889a5d5..99f8e22 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -374,19 +374,49 @@
/*
* If type at "offset" isn't already VAR_STRING then generate ISN_2STRING.
+ * But only for simple types.
*/
static int
may_generate_2STRING(int offset, cctx_T *cctx)
{
isn_T *isn;
+ isntype_T isntype = ISN_2STRING;
garray_T *stack = &cctx->ctx_type_stack;
type_T **type = ((type_T **)stack->ga_data) + stack->ga_len + offset;
- if ((*type)->tt_type == VAR_STRING)
- return OK;
- *type = &t_string;
+ switch ((*type)->tt_type)
+ {
+ // nothing to be done
+ case VAR_STRING: return OK;
- if ((isn = generate_instr(cctx, ISN_2STRING)) == NULL)
+ // conversion possible
+ case VAR_SPECIAL:
+ case VAR_BOOL:
+ case VAR_NUMBER:
+ case VAR_FLOAT:
+ break;
+
+ // conversion possible (with runtime check)
+ case VAR_ANY:
+ case VAR_UNKNOWN:
+ isntype = ISN_2STRING_ANY;
+ break;
+
+ // conversion not possible
+ case VAR_VOID:
+ case VAR_BLOB:
+ case VAR_FUNC:
+ case VAR_PARTIAL:
+ case VAR_LIST:
+ case VAR_DICT:
+ case VAR_JOB:
+ case VAR_CHANNEL:
+ to_string_error((*type)->tt_type);
+ return FAIL;
+ }
+
+ *type = &t_string;
+ if ((isn = generate_instr(cctx, isntype)) == NULL)
return FAIL;
isn->isn_arg.number = offset;
@@ -7005,6 +7035,7 @@
case ISN_2BOOL:
case ISN_2STRING:
+ case ISN_2STRING_ANY:
case ISN_ADDBLOB:
case ISN_ADDLIST:
case ISN_BCALL: