comparison src/typval.c @ 33678:7d9d2404a3d4 v9.0.2076

patch 9.0.2076: Vim9: No support for type aliases Commit: https://github.com/vim/vim/commit/ec3cebbd2b6b7583d2f683f5e66345163ec122aa Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Oct 27 19:35:26 2023 +0200 patch 9.0.2076: Vim9: No support for type aliases Problem: Vim9: No support for type aliases Solution: Implement :type command A type definition is giving a name to a type specification. This also known type alias. :type ListOfStrings = list<string> The type alias can be used wherever a built-in type can be used. The type alias name must start with an upper case character. closes: #13407 Signed-off-by: Christian Brabandt <cb@256bit.org> Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author Christian Brabandt <cb@256bit.org>
date Fri, 27 Oct 2023 19:45:05 +0200
parents e9c70470fe94
children f126ffc85f7c
comparison
equal deleted inserted replaced
33677:96debbc2abd9 33678:7d9d2404a3d4
88 case VAR_CLASS: 88 case VAR_CLASS:
89 class_unref(varp->vval.v_class); 89 class_unref(varp->vval.v_class);
90 break; 90 break;
91 case VAR_OBJECT: 91 case VAR_OBJECT:
92 object_unref(varp->vval.v_object); 92 object_unref(varp->vval.v_object);
93 break;
94
95 case VAR_TYPEALIAS:
96 typealias_unref(varp->vval.v_typealias);
93 break; 97 break;
94 98
95 case VAR_NUMBER: 99 case VAR_NUMBER:
96 case VAR_FLOAT: 100 case VAR_FLOAT:
97 case VAR_ANY: 101 case VAR_ANY:
166 varp->vval.v_class = NULL; 170 varp->vval.v_class = NULL;
167 break; 171 break;
168 case VAR_OBJECT: 172 case VAR_OBJECT:
169 object_unref(varp->vval.v_object); 173 object_unref(varp->vval.v_object);
170 varp->vval.v_object = NULL; 174 varp->vval.v_object = NULL;
175 break;
176 case VAR_TYPEALIAS:
177 typealias_unref(varp->vval.v_typealias);
178 varp->vval.v_typealias = NULL;
171 break; 179 break;
172 case VAR_UNKNOWN: 180 case VAR_UNKNOWN:
173 case VAR_ANY: 181 case VAR_ANY:
174 case VAR_VOID: 182 case VAR_VOID:
175 break; 183 break;
260 emsg(_(e_using_object_as_number)); 268 emsg(_(e_using_object_as_number));
261 break; 269 break;
262 case VAR_VOID: 270 case VAR_VOID:
263 emsg(_(e_cannot_use_void_value)); 271 emsg(_(e_cannot_use_void_value));
264 break; 272 break;
273 case VAR_TYPEALIAS:
274 semsg(_(e_using_typealias_as_variable),
275 varp->vval.v_typealias->ta_name);
276 break;
265 case VAR_UNKNOWN: 277 case VAR_UNKNOWN:
266 case VAR_ANY: 278 case VAR_ANY:
267 case VAR_INSTR: 279 case VAR_INSTR:
268 internal_error_no_abort("tv_get_number(UNKNOWN)"); 280 internal_error_no_abort("tv_get_number(UNKNOWN)");
269 break; 281 break;
376 case VAR_OBJECT: 388 case VAR_OBJECT:
377 emsg(_(e_using_object_as_float)); 389 emsg(_(e_using_object_as_float));
378 break; 390 break;
379 case VAR_VOID: 391 case VAR_VOID:
380 emsg(_(e_cannot_use_void_value)); 392 emsg(_(e_cannot_use_void_value));
393 break;
394 case VAR_TYPEALIAS:
395 semsg(_(e_using_typealias_as_variable),
396 varp->vval.v_typealias->ta_name);
381 break; 397 break;
382 case VAR_UNKNOWN: 398 case VAR_UNKNOWN:
383 case VAR_ANY: 399 case VAR_ANY:
384 case VAR_INSTR: 400 case VAR_INSTR:
385 internal_error_no_abort("tv_get_float(UNKNOWN)"); 401 internal_error_no_abort("tv_get_float(UNKNOWN)");
1127 #endif 1143 #endif
1128 break; 1144 break;
1129 case VAR_VOID: 1145 case VAR_VOID:
1130 emsg(_(e_cannot_use_void_value)); 1146 emsg(_(e_cannot_use_void_value));
1131 break; 1147 break;
1148 case VAR_TYPEALIAS:
1132 case VAR_UNKNOWN: 1149 case VAR_UNKNOWN:
1133 case VAR_ANY: 1150 case VAR_ANY:
1134 case VAR_INSTR: 1151 case VAR_INSTR:
1135 semsg(_(e_using_invalid_value_as_string_str), 1152 semsg(_(e_using_invalid_value_as_string_str),
1136 vartype_name(varp->v_type)); 1153 vartype_name(varp->v_type));
1286 to->vval.v_dict = NULL; 1303 to->vval.v_dict = NULL;
1287 else 1304 else
1288 { 1305 {
1289 to->vval.v_dict = from->vval.v_dict; 1306 to->vval.v_dict = from->vval.v_dict;
1290 ++to->vval.v_dict->dv_refcount; 1307 ++to->vval.v_dict->dv_refcount;
1308 }
1309 break;
1310 case VAR_TYPEALIAS:
1311 if (from->vval.v_typealias == NULL)
1312 to->vval.v_typealias = NULL;
1313 else
1314 {
1315 to->vval.v_typealias = from->vval.v_typealias;
1316 ++to->vval.v_typealias->ta_refcount;
1291 } 1317 }
1292 break; 1318 break;
1293 case VAR_VOID: 1319 case VAR_VOID:
1294 emsg(_(e_cannot_use_void_value)); 1320 emsg(_(e_cannot_use_void_value));
1295 break; 1321 break;
1594 return tv->vval.v_number == 0; 1620 return tv->vval.v_number == 0;
1595 break; 1621 break;
1596 case VAR_FLOAT: if (!in_vim9script()) 1622 case VAR_FLOAT: if (!in_vim9script())
1597 return tv->vval.v_float == 0.0; 1623 return tv->vval.v_float == 0.0;
1598 break; 1624 break;
1625 case VAR_TYPEALIAS: return tv->vval.v_typealias == NULL;
1599 default: break; 1626 default: break;
1600 } 1627 }
1601 } 1628 }
1602 // although comparing null with number, float or bool is not very useful 1629 // although comparing null with number, float or bool is not very useful
1603 // we won't give an error 1630 // we won't give an error
2067 return tv1->vval.v_partial == tv2->vval.v_partial; 2094 return tv1->vval.v_partial == tv2->vval.v_partial;
2068 2095
2069 case VAR_FUNC: 2096 case VAR_FUNC:
2070 return tv1->vval.v_string == tv2->vval.v_string; 2097 return tv1->vval.v_string == tv2->vval.v_string;
2071 2098
2099 case VAR_TYPEALIAS:
2100 return tv1->vval.v_typealias == tv2->vval.v_typealias;
2101
2072 case VAR_UNKNOWN: 2102 case VAR_UNKNOWN:
2073 case VAR_ANY: 2103 case VAR_ANY:
2074 case VAR_VOID: 2104 case VAR_VOID:
2075 break; 2105 break;
2076 } 2106 }