]> Nishi Git Mirror - gwion.git/commitdiff
:art: Allow cast to self type
authorfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 19 Jul 2019 12:47:27 +0000 (14:47 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 19 Jul 2019 12:47:27 +0000 (14:47 +0200)
src/lib/object.c
src/lib/opfunc.c

index 8df093bbd5c8726d22ce95a091f6e3ef2b1e8114..d9b3175c32ec3a5071f0b6cd3f39225881fd9f53 100644 (file)
@@ -214,6 +214,9 @@ GWION_IMPORT(object) {
   GWI_BB(gwi_oper_add(gwi, at_object))
   GWI_BB(gwi_oper_emi(gwi, opem_at_object))
   GWI_BB(gwi_oper_end(gwi, "@=>", ObjectAssign))
+  GWI_BB(gwi_oper_ini(gwi, OP_ANY_TYPE, OP_ANY_TYPE, NULL))
+  GWI_BB(gwi_oper_add(gwi, opck_basic_cast))
+  GWI_BB(gwi_oper_end(gwi, "$", NULL))
   GWI_BB(gwi_oper_ini(gwi, "Object", "Object", "int"))
   GWI_BB(gwi_oper_end(gwi, "==",  EqObject))
   GWI_BB(gwi_oper_end(gwi, "!=", NeqObject))
index 3f2f752216c81931dcbd20320d379b922c2835e5..ace7ddef2c7d4e4b3d73c5bbde92c22e19b30415 100644 (file)
@@ -19,7 +19,8 @@ static inline m_str access(ae_Exp_Meta meta) {
 
 OP_CHECK(opck_basic_cast) {
   const Exp_Cast* cast = (Exp_Cast*)data;
-  return exp_self(cast)->type;
+  return isa(cast->exp->type, exp_self(cast)->type) > 0 ?
+     exp_self(cast)->type : t_null;
 }
 
 OP_EMIT(opem_basic_cast) {