comparison src/vim9compile.c @ 24390:492f7b54f691 v8.2.2735

patch 8.2.2735: Vim9: function reference found with prefix, not without Commit: https://github.com/vim/vim/commit/fa5963880df1d11613594ab78c0a68f894d34aa3 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Apr 7 21:58:16 2021 +0200 patch 8.2.2735: Vim9: function reference found with prefix, not without Problem: Vim9: function reference found with prefix, not without. Solution: Also find function reference without prefix.
author Bram Moolenaar <Bram@vim.org>
date Wed, 07 Apr 2021 22:00:04 +0200
parents 72f3e40f046c
children 62e978382fa0
comparison
equal deleted inserted replaced
24389:9b13404bbb6f 24390:492f7b54f691
2887 int res = FAIL; 2887 int res = FAIL;
2888 int prev_called_emsg = called_emsg; 2888 int prev_called_emsg = called_emsg;
2889 2889
2890 if (*(*arg + 1) == ':') 2890 if (*(*arg + 1) == ':')
2891 { 2891 {
2892 // load namespaced variable
2893 if (end <= *arg + 2) 2892 if (end <= *arg + 2)
2894 { 2893 {
2895 isntype_T isn_type; 2894 isntype_T isn_type;
2896 2895
2896 // load dictionary of namespace
2897 switch (**arg) 2897 switch (**arg)
2898 { 2898 {
2899 case 'g': isn_type = ISN_LOADGDICT; break; 2899 case 'g': isn_type = ISN_LOADGDICT; break;
2900 case 'w': isn_type = ISN_LOADWDICT; break; 2900 case 'w': isn_type = ISN_LOADWDICT; break;
2901 case 't': isn_type = ISN_LOADTDICT; break; 2901 case 't': isn_type = ISN_LOADTDICT; break;
2910 } 2910 }
2911 else 2911 else
2912 { 2912 {
2913 isntype_T isn_type = ISN_DROP; 2913 isntype_T isn_type = ISN_DROP;
2914 2914
2915 // load namespaced variable
2915 name = vim_strnsave(*arg + 2, end - (*arg + 2)); 2916 name = vim_strnsave(*arg + 2, end - (*arg + 2));
2916 if (name == NULL) 2917 if (name == NULL)
2917 return FAIL; 2918 return FAIL;
2918 2919
2919 switch (**arg) 2920 switch (**arg)
2920 { 2921 {
2921 case 'v': res = generate_LOADV(cctx, name, error); 2922 case 'v': res = generate_LOADV(cctx, name, error);
2922 break; 2923 break;
2923 case 's': res = compile_load_scriptvar(cctx, name, 2924 case 's': if (is_expr && ASCII_ISUPPER(*name)
2925 && find_func(name, FALSE, cctx) != NULL)
2926 res = generate_funcref(cctx, name);
2927 else
2928 res = compile_load_scriptvar(cctx, name,
2924 NULL, &end, error); 2929 NULL, &end, error);
2925 break; 2930 break;
2926 case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL) 2931 case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
2927 isn_type = ISN_LOADG; 2932 {
2933 if (is_expr && ASCII_ISUPPER(*name)
2934 && find_func(name, FALSE, cctx) != NULL)
2935 res = generate_funcref(cctx, name);
2936 else
2937 isn_type = ISN_LOADG;
2938 }
2928 else 2939 else
2929 { 2940 {
2930 isn_type = ISN_LOADAUTO; 2941 isn_type = ISN_LOADAUTO;
2931 vim_free(name); 2942 vim_free(name);
2932 name = vim_strnsave(*arg, end - *arg); 2943 name = vim_strnsave(*arg, end - *arg);
2943 } 2954 }
2944 if (isn_type != ISN_DROP) 2955 if (isn_type != ISN_DROP)
2945 { 2956 {
2946 // Global, Buffer-local, Window-local and Tabpage-local 2957 // Global, Buffer-local, Window-local and Tabpage-local
2947 // variables can be defined later, thus we don't check if it 2958 // variables can be defined later, thus we don't check if it
2948 // exists, give error at runtime. 2959 // exists, give an error at runtime.
2949 res = generate_LOAD(cctx, isn_type, 0, name, &t_any); 2960 res = generate_LOAD(cctx, isn_type, 0, name, &t_any);
2950 } 2961 }
2951 } 2962 }
2952 } 2963 }
2953 else 2964 else
2986 if (script_var_exists(*arg, len, cctx) == OK 2997 if (script_var_exists(*arg, len, cctx) == OK
2987 || find_imported(name, 0, cctx) != NULL) 2998 || find_imported(name, 0, cctx) != NULL)
2988 res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE); 2999 res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
2989 3000
2990 // When evaluating an expression and the name starts with an 3001 // When evaluating an expression and the name starts with an
2991 // uppercase letter or "x:" it can be a user defined function. 3002 // uppercase letter it can be a user defined function.
2992 // TODO: this is just guessing 3003 // generate_funcref() will fail if the function can't be found.
2993 if (res == FAIL && is_expr 3004 if (res == FAIL && is_expr && ASCII_ISUPPER(*name))
2994 && (ASCII_ISUPPER(*name) || name[1] == ':'))
2995 res = generate_funcref(cctx, name); 3005 res = generate_funcref(cctx, name);
2996 } 3006 }
2997 } 3007 }
2998 if (gen_load) 3008 if (gen_load)
2999 res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type); 3009 res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type);