comparison src/vim9type.c @ 33913:a259471e74fe v9.0.2156

patch 9.0.2156: Vim9: can use typealias in assignment Commit: https://github.com/vim/vim/commit/9ed53752df1020a6881ac68d1bde2852c9a680aa Author: Ernie Rael <errael@raelity.com> Date: Mon Dec 11 17:40:46 2023 +0100 patch 9.0.2156: Vim9: can use typealias in assignment Problem: Vim9: can use typealias in an assignment Solution: Generate errors when class/typealias involved in the rhs of an assignment closes: #13637 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Christian Brabandt <cb@256bit.org> Generate errors when class/typealias involved in assignment.
author Christian Brabandt <cb@256bit.org>
date Mon, 11 Dec 2023 17:45:06 +0100
parents a9ccbadecda1
children a49ae967e9ed
comparison
equal deleted inserted replaced
33912:bc834a974df8 33913:a259471e74fe
1844 rettv->vval.v_string = vim_strsave((char_u *)name); 1844 rettv->vval.v_string = vim_strsave((char_u *)name);
1845 } 1845 }
1846 clear_type_list(&type_list); 1846 clear_type_list(&type_list);
1847 } 1847 }
1848 1848
1849 /*
1850 * Check if the typval_T is a value type; report an error if it is not.
1851 * Note: a type, user defined or typealias, is not a value type.
1852 *
1853 * Return OK if it's a value type, else FAIL
1854 */
1855 int
1856 check_typval_is_value(typval_T *tv)
1857 {
1858 if (tv->v_type == VAR_CLASS)
1859 {
1860 semsg(_(e_using_class_as_value_str), tv->vval.v_class->class_name);
1861 return FAIL;
1862 }
1863 else if (tv->v_type == VAR_TYPEALIAS)
1864 {
1865 semsg(_(e_using_typealias_as_value_str), tv->vval.v_typealias->ta_name);
1866 return FAIL;
1867 }
1868 return OK;
1869 }
1870
1871 /*
1872 * Same as above, except check type_T.
1873 */
1874 int
1875 check_type_is_value(type_T *type)
1876 {
1877 if (type->tt_type == VAR_CLASS)
1878 {
1879 semsg(_(e_using_class_as_value_str), type->tt_class->class_name);
1880 return FAIL;
1881 }
1882 else if (type->tt_type == VAR_TYPEALIAS)
1883 {
1884 // Not sure what could be done here to get a name
1885 // TODO: MAYBE AN OPTIONAL ARGUMENT
1886 emsg(_(e_using_typealias_as_var_val));
1887 return FAIL;
1888 }
1889 return OK;
1890 }
1891
1892 /*
1893 * Same as above, except check vartype_T.
1894 */
1895 int
1896 check_vartype_is_value(vartype_T typ)
1897 {
1898 if (typ == VAR_CLASS)
1899 {
1900 emsg(_(e_using_class_as_var_val));
1901 return FAIL;
1902 }
1903 else if (typ == VAR_TYPEALIAS)
1904 {
1905 emsg(_(e_using_typealias_as_var_val));
1906 return FAIL;
1907 }
1908 return OK;
1909 }
1910
1849 #endif // FEAT_EVAL 1911 #endif // FEAT_EVAL