From 0bfab33ce998eef85752ae022d5c684717b63c4e Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Fri, 3 May 2013 09:23:56 -0700 Subject: [PATCH] Fix logic fail and unsets in DefineConstant() If we infer the type, then we already know its integer type ID. Trying to then parse that type leads to "Undefined type" errors (but it still functions due to the fallthrough). This diff skips trying to parse a known type and thus avoids the misleading error message. Also guard against missing funcs/consts elements in global scope and classes. --- hphp/idl/base.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hphp/idl/base.php b/hphp/idl/base.php index 3c58ca58e..3270dcc5d 100644 --- a/hphp/idl/base.php +++ b/hphp/idl/base.php @@ -280,12 +280,13 @@ function idl_infer_type($v) { function DefineConstant($const) { global $constants, $classes, $current_class; + if (!isset($const['type']) && array_key_exists('value', $const)) { $const['type'] = idl_infer_type($const['value']); + } else { + $const['type'] = idl_parse_type($const['type']); } - $const['type'] = idl_parse_type($const['type']); - if (empty($current_class)) { $constants[] = $const; } else { @@ -370,17 +371,21 @@ function DefineFunction($func) { function ReadIDLFile($path) { $entries = json_decode(file_get_contents($path), /* use arrays */ true); - foreach ($entries['funcs'] as $func) { - DefineFunction($func); + if (!empty($entries['funcs'])) { + foreach ($entries['funcs'] as $func) { + DefineFunction($func); + } } - foreach ($entries['consts'] as $const) { - DefineConstant($const); + if (!empty($entries['consts'])) { + foreach ($entries['consts'] as $const) { + DefineConstant($const); + } } foreach ($entries['classes'] as $class) { - $methods = $class['funcs']; - $consts = $class['consts']; + $methods = isset($class['funcs']) ? $class['funcs'] : array(); + $consts = isset($class['consts']) ? $class['consts'] : array(); unset($class['funcs']); unset($class['consts']);