From 02412f515deeaf05d0899a13bf52d310cbaa683f Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Fri, 12 Jul 2024 13:11:26 +0300 Subject: [PATCH] Disallowing for now binding of any types for struct fields --- src/bind.inc.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/bind.inc.php b/src/bind.inc.php index 56345f8..5ea33e3 100644 --- a/src/bind.inc.php +++ b/src/bind.inc.php @@ -30,6 +30,8 @@ function codegen( array $options = array() ) { + validate_meta($meta); + $twig = get_twig(); if($tpl_cache_dir) $twig->setCache($tpl_cache_dir); @@ -76,6 +78,21 @@ function get_twig(array $inc_path = []) return $twig; } +function validate_meta(\mtgMetaInfo $meta) +{ + foreach($meta->getUnits() as $u) + { + if($u->object instanceof \mtgMetaStruct) + { + //NOTE: disallowing for now bindings to 'any' types for structs + foreach($u->object->getFields() as $fld) + if($fld->getType() == "any" || $fld->getType() == "any[]") + throw new Exception("Field '{$fld->getName()}' in struct '{$u->object->getName()}' has unsupported for binding type '{$fld->getType()}'"); + } + } +} + +//TODO: call it always inside codegen? function prepare_meta(\mtgMetaInfo $orig) { //NOTE: making a deep clone @@ -89,6 +106,7 @@ function prepare_meta(\mtgMetaInfo $orig) return $meta; } + function _make_arr_proxies(array &$arr_proxies, \mtgMetaInfo $meta, ?\mtgType $type, array &$traversed) { if($type == null)