improved type validation
[m6w6/ext-psi] / src / types / let_exp.c
index 1d8e2ec93b8a92d6c280a364fdac8aa18a07f302..4600abfe37568ebce796de9e4a4dbc339d5695a1 100644 (file)
@@ -26,6 +26,7 @@
 #include "php_psi_stdinc.h"
 #include "data.h"
 #include "call.h"
+#include "calc.h"
 
 #include <assert.h>
 
@@ -247,8 +248,8 @@ void *psi_let_exp_exec(struct psi_let_exp *val, struct psi_decl_arg *darg,
 
        case PSI_LET_CALLOC:
                {
-                       zend_long n = psi_long_num_exp(val->data.alloc->nmemb, frame);
-                       zend_long s = psi_long_num_exp(val->data.alloc->size, frame);
+                       zend_long n = psi_long_num_exp(val->data.alloc->nmemb, frame, NULL);
+                       zend_long s = psi_long_num_exp(val->data.alloc->size, frame, NULL);
                        void *tmp = *psi_call_frame_push_auto(frame,
                                        safe_emalloc(n, s, sizeof(void *)));
 
@@ -258,7 +259,17 @@ void *psi_let_exp_exec(struct psi_let_exp *val, struct psi_decl_arg *darg,
                break;
 
        case PSI_LET_NUMEXP:
-               frame_sym->temp_val.zend.lval = psi_long_num_exp(val->data.num, frame);
+               {
+                       impl_val res;
+                       token_t val_type = psi_decl_type_get_real(val->var->arg->type)->type;
+                       token_t res_type = psi_num_exp_exec(val->data.num, &res, frame, NULL);
+
+                       if (val_type == res_type) {
+                               frame_sym->temp_val = res;
+                       } else {
+                               psi_calc_cast(res_type, &res, val_type, &frame_sym->temp_val);
+                       }
+               }
                break;
 
        case PSI_LET_CALLBACK: