forked from aniani/vim
patch 9.0.1054: object member can't get type from initializer
Problem: Object member can't get type from initializer. Solution: If there is no type specified try to use the type of the initializer. Check for a valid type.
This commit is contained in:
@@ -425,6 +425,17 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int flags)
|
||||
return &t_number;
|
||||
if (tv->v_type == VAR_BOOL)
|
||||
return &t_bool;
|
||||
if (tv->v_type == VAR_SPECIAL)
|
||||
{
|
||||
if (tv->vval.v_number == VVAL_NULL)
|
||||
return &t_null;
|
||||
if (tv->vval.v_number == VVAL_NONE)
|
||||
return &t_none;
|
||||
if (tv->vval.v_number == VVAL_TRUE
|
||||
|| tv->vval.v_number == VVAL_TRUE)
|
||||
return &t_bool;
|
||||
return &t_unknown;
|
||||
}
|
||||
if (tv->v_type == VAR_STRING)
|
||||
return &t_string;
|
||||
if (tv->v_type == VAR_BLOB)
|
||||
@@ -619,6 +630,25 @@ typval2type(typval_T *tv, int copyID, garray_T *type_gap, int flags)
|
||||
return type;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE if "type" can be used for a variable declaration.
|
||||
* Give an error and return FALSE if not.
|
||||
*/
|
||||
int
|
||||
valid_declaration_type(type_T *type)
|
||||
{
|
||||
if (type->tt_type == VAR_SPECIAL // null, none
|
||||
|| type->tt_type == VAR_VOID)
|
||||
{
|
||||
char *tofree = NULL;
|
||||
char *name = type_name(type, &tofree);
|
||||
semsg(_(e_invalid_type_for_object_member_str), name);
|
||||
vim_free(tofree);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a type_T for a typval_T, used for v: variables.
|
||||
* "type_list" is used to temporarily create types in.
|
||||
|
Reference in New Issue
Block a user