static char_u *
get_lval_imported(
lval_T *lp,
- typval_T *rettv,
scid_T imp_sid,
char_u *p,
dictitem_T **dip,
- int fne_flags,
- int vim9script)
+ int fne_flags)
{
ufunc_T *ufunc;
type_T *type = NULL;
TRUE) == -1)
goto failed;
- if (vim9script && type != NULL)
- {
- where_T where = WHERE_INIT;
-
- // In a vim9 script, do type check and make sure the variable is
- // writable.
- if (check_typval_type(type, rettv, where) == FAIL)
- goto failed;
- }
-
// Get the typval for the exported item
hashtab_T *ht = &SCRIPT_VARS(imp_sid);
if (ht == NULL)
goto failed;
lp->ll_tv = &di->di_tv;
+ lp->ll_valtype = type;
success:
rc = OK;
if (import != NULL)
{
p++; // skip '.'
- p = get_lval_imported(lp, rettv, import->imp_sid, p, &v,
- fne_flags, vim9script);
+ p = get_lval_imported(lp, import->imp_sid, p, &v, fne_flags);
if (p == NULL)
return NULL;
}
== FAIL)
return NULL;
}
+
+ if (!lp->ll_range)
+ // Indexing a single byte in a blob. So the rhs type is a
+ // number.
+ lp->ll_valtype = &t_number;
+
lp->ll_blob = lp->ll_tv->vval.v_blob;
lp->ll_tv = NULL;
break;
return NULL;
}
- if (lp->ll_valtype != NULL)
+ if (lp->ll_valtype != NULL && !lp->ll_range)
// use the type of the member
lp->ll_valtype = lp->ll_valtype->tt_member;
}
}
+ if (vim9script && lp->ll_valtype != NULL && rettv != NULL)
+ {
+ where_T where = WHERE_INIT;
+
+ // In a vim9 script, do type check and make sure the variable is
+ // writable.
+ if (check_typval_type(lp->ll_valtype, rettv, where) == FAIL)
+ return NULL;
+ }
+
+
clear_tv(&var1);
lp->ll_name_end = p;
return p;
&rtp = save_rtp
enddef
+" Test for changing the value of an imported Dict item
+def Test_set_imported_dict_item()
+ var lines =<< trim END
+ vim9script
+ export var dict1: dict<bool> = {bflag: false}
+ export var dict2: dict<dict<bool>> = {x: {bflag: false}}
+ END
+ writefile(lines, 'XimportedDict.vim', 'D')
+
+ lines =<< trim END
+ vim9script
+ import './XimportedDict.vim'
+ assert_equal(XimportedDict.dict1.bflag, false)
+ XimportedDict.dict1.bflag = true
+ assert_equal(XimportedDict.dict1.bflag, true)
+ XimportedDict.dict2.x.bflag = true
+ assert_equal(XimportedDict.dict2.x.bflag, true)
+ assert_equal('bool', typename(XimportedDict.dict1.bflag))
+ assert_equal('bool', typename(XimportedDict.dict2.x.bflag))
+ assert_equal('bool', typename(XimportedDict.dict2['x'].bflag))
+ assert_equal('bool', typename(XimportedDict.dict2.x['bflag']))
+
+ assert_equal(XimportedDict.dict1['bflag'], true)
+ XimportedDict.dict1['bflag'] = false
+ assert_equal(XimportedDict.dict1.bflag, false)
+ XimportedDict.dict2['x']['bflag'] = false
+ assert_equal(XimportedDict.dict2['x'].bflag, false)
+ END
+ v9.CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ import './XimportedDict.vim'
+ XimportedDict.dict2.x.bflag = []
+ END
+ v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected bool but got list<any>', 3)
+enddef
+
+" Test for changing the value of an imported class member
+def Test_set_imported_class_member()
+ var lines =<< trim END
+ vim9script
+ export class Config
+ public static var option = false
+ endclass
+ END
+ writefile(lines, 'XimportedClass.vim', 'D')
+
+ lines =<< trim END
+ vim9script
+ import './XimportedClass.vim' as foo
+ type FooConfig = foo.Config
+ assert_equal(false, FooConfig.option)
+ assert_equal(false, foo.Config.option)
+ foo.Config.option = true
+ assert_equal(true, foo.Config.option)
+ assert_equal(true, FooConfig.option)
+ END
+ v9.CheckScriptSuccess(lines)
+enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker