deref_func_name(
	char_u	    *name,
	int	    *lenp,
	partial_T   **partialp,
	type_T	    **type,
	int	    no_autoload,
	int	    *found_var)
{
    dictitem_T	*v;
    typval_T	*tv = NULL;
    int		cc;
    char_u	*s = NULL;
    hashtab_T	*ht;
    int		did_type = FALSE;

    if (partialp != NULL)
	*partialp = NULL;

    cc = name[*lenp];
    name[*lenp] = NUL;

    v = find_var(name, &ht, no_autoload);
    name[*lenp] = cc;
    if (v != NULL)
    {
	tv = &v->di_tv;
    }
    else if (in_vim9script() || STRNCMP(name, "s:", 2) == 0)
    {
	imported_T  *import;
	char_u	    *p = name;
	int	    len = *lenp;

	if (STRNCMP(name, "s:", 2) == 0)
	{
	    p = name + 2;
	    len -= 2;
	}
	import = find_imported(p, len, NULL);

	// imported variable from another script
	if (import != NULL)
	{
	    if (import->imp_funcname != NULL)
	    {
		s = import->imp_funcname;
		*lenp = (int)STRLEN(s);
		return s;
	    }
	    if (import->imp_flags & IMP_FLAGS_STAR)
	    {
		name[len] = NUL;
		semsg(_(e_cannot_use_str_itself_it_is_imported_with_star),
									 name);
		name[len] = cc;
		*lenp = 0;
		return (char_u *)"";	// just in case
	    }
	    else
	    {
		scriptitem_T    *si = SCRIPT_ITEM(import->imp_sid);
		svar_T		*sv = ((svar_T *)si->sn_var_vals.ga_data)
						    + import->imp_var_vals_idx;
		tv = sv->sv_tv;
		if (type != NULL)
		    *type = sv->sv_type;
		did_type = TRUE;
	    }
	}
    }

    if (tv != NULL)
    {
	if (found_var != NULL)
	    *found_var = TRUE;
	if (tv->v_type == VAR_FUNC)
	{
	    if (tv->vval.v_string == NULL)
	    {
		*lenp = 0;
		return (char_u *)"";	// just in case
	    }
	    s = tv->vval.v_string;
	    *lenp = (int)STRLEN(s);
	}

	if (tv->v_type == VAR_PARTIAL)
	{
	    partial_T *pt = tv->vval.v_partial;

	    if (pt == NULL)
	    {
		*lenp = 0;
		return (char_u *)"";	// just in case
	    }
	    if (partialp != NULL)
		*partialp = pt;
	    s = partial_name(pt);
	    *lenp = (int)STRLEN(s);
	}

	if (s != NULL)
	{
	    if (!did_type && type != NULL && ht == get_script_local_ht())
	    {
		svar_T  *sv = find_typval_in_script(tv);

		if (sv != NULL)
		    *type = sv->sv_type;
	    }
	    return s;
	}
    }

    return name;
}
deref_func_name(
	char_u	    *name,
	int	    *lenp,
	partial_T   **partialp,
	type_T	    **type,
	int	    no_autoload,
	int	    *found_var)
{
    dictitem_T	*v;
    typval_T	*tv = NULL;
    int		cc;
    char_u	*s = NULL;
    hashtab_T	*ht;
    int		did_type = FALSE;

    if (partialp != NULL)
	*partialp = NULL;

    cc = name[*lenp];
    name[*lenp] = NUL;

    v = find_var(name, &ht, no_autoload);
    name[*lenp] = cc;
    if (v != NULL)
    {
	tv = &v->di_tv;
    }
    else if (in_vim9script() || STRNCMP(name, "s:", 2) == 0)
    {
	imported_T  *import;
	char_u	    *p = name;
	int	    len = *lenp;

	if (STRNCMP(name, "s:", 2) == 0)
	{
	    p = name + 2;
	    len -= 2;
	}
	import = find_imported(p, len, NULL);

	 
	if (import != NULL)
	{
	    if (import->imp_funcname != NULL)
	    {
		s = import->imp_funcname;
		*lenp = (int)STRLEN(s);
		return s;
	    }
	    if (import->imp_flags & IMP_FLAGS_STAR)
	    {
		name[len] = NUL;
		semsg(_(e_cannot_use_str_itself_it_is_imported_with_star),
									 name);
		name[len] = cc;
		*lenp = 0;
		return (char_u *)"";	 
	    }
	    else
	    {
		scriptitem_T    *si = SCRIPT_ITEM(import->imp_sid);
		svar_T		*sv = ((svar_T *)si->sn_var_vals.ga_data)
						    + import->imp_var_vals_idx;
		tv = sv->sv_tv;
		if (type != NULL)
		    *type = sv->sv_type;
		did_type = TRUE;
	    }
	}
    }

    if (tv != NULL)
    {
	if (found_var != NULL)
	    *found_var = TRUE;
	if (tv->v_type == VAR_FUNC)
	{
	    if (tv->vval.v_string == NULL)
	    {
		*lenp = 0;
		return (char_u *)"";	 
	    }
	    s = tv->vval.v_string;
	    *lenp = (int)STRLEN(s);
	}

	if (tv->v_type == VAR_PARTIAL)
	{
	    partial_T *pt = tv->vval.v_partial;

	    if (pt == NULL)
	    {
		*lenp = 0;
		return (char_u *)"";	 
	    }
	    if (partialp != NULL)
		*partialp = pt;
	    s = partial_name(pt);
	    *lenp = (int)STRLEN(s);
	}

	if (s != NULL)
	{
	    if (!did_type && type != NULL && ht == get_script_local_ht())
	    {
		svar_T  *sv = find_typval_in_script(tv);

		if (sv != NULL)
		    *type = sv->sv_type;
	    }
	    return s;
	}
    }

    return name;
}