From cd5e74ec7edd7053e5213d67debff92cb4238650 Mon Sep 17 00:00:00 2001 From: mwilliams Date: Wed, 24 Jul 2013 13:25:55 -0700 Subject: [PATCH] Fix type inference for ZendParamMode Parameters of ZendParamMode functions aren't converted to the destination type, so don't try to apply a type. --- hphp/compiler/analysis/function_scope.cpp | 11 ++++++++--- hphp/compiler/analysis/function_scope.h | 1 + hphp/system/idl/math.idl.json | 3 ++- hphp/test/slow/ext_math/sqrt.php | 6 ++++++ hphp/test/slow/ext_math/sqrt.php.expect | 3 +++ 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 hphp/test/slow/ext_math/sqrt.php create mode 100644 hphp/test/slow/ext_math/sqrt.php.expect diff --git a/hphp/compiler/analysis/function_scope.cpp b/hphp/compiler/analysis/function_scope.cpp index 552476eed..5446a09f5 100644 --- a/hphp/compiler/analysis/function_scope.cpp +++ b/hphp/compiler/analysis/function_scope.cpp @@ -279,6 +279,10 @@ void FunctionScope::setParamSpecs(AnalysisResultPtr ar) { } } +bool FunctionScope::isZendParamMode() const { + return m_attributeClassInfo & ClassInfo::ZendParamMode; +} + bool FunctionScope::isPublic() const { return m_modifiers && m_modifiers->isPublic(); } @@ -652,7 +656,8 @@ int FunctionScope::inferParamTypes(AnalysisResultPtr ar, ConstructPtr exp, /** * Duplicate the logic of getParamType(i), w/o the mutation */ - TypePtr paramType(i < m_maxParam ? m_paramTypes[i] : TypePtr()); + TypePtr paramType(i < m_maxParam && !isZendParamMode() ? + m_paramTypes[i] : TypePtr()); if (!paramType) paramType = Type::Some; if (valid && !canSetParamType && i < m_maxParam && (!Option::HardTypeHints || !m_paramTypeSpecs[i])) { @@ -664,8 +669,8 @@ int FunctionScope::inferParamTypes(AnalysisResultPtr ar, ConstructPtr exp, * expression since it'll just get converted anyways. Doing it this way * allows us to generate less temporaries along the way. */ - TypePtr optParamType( - paramType->is(Type::KindOfVariant) ? Type::Some : paramType); + TypePtr optParamType(paramType->is(Type::KindOfVariant) ? + Type::Some : paramType); expType = param->inferAndCheck(ar, optParamType, false); } else { expType = param->inferAndCheck(ar, Type::Some, false); diff --git a/hphp/compiler/analysis/function_scope.h b/hphp/compiler/analysis/function_scope.h index 368755d3e..33db6f813 100644 --- a/hphp/compiler/analysis/function_scope.h +++ b/hphp/compiler/analysis/function_scope.h @@ -109,6 +109,7 @@ public: bool hasImpl() const; void setDirectInvoke() { m_directInvoke = true; } bool hasDirectInvoke() const { return m_directInvoke; } + bool isZendParamMode() const; bool mayContainThis(); bool isClosure() const; bool isGenerator() const; diff --git a/hphp/system/idl/math.idl.json b/hphp/system/idl/math.idl.json index 191e35eb9..11ab6e23b 100644 --- a/hphp/system/idl/math.idl.json +++ b/hphp/system/idl/math.idl.json @@ -788,7 +788,8 @@ "name": "sqrt", "desc": "Returns the square root of arg.", "flags": [ - "HasDocComment" + "HasDocComment", + "ZendParamMode" ], "return": { "type": "Double", diff --git a/hphp/test/slow/ext_math/sqrt.php b/hphp/test/slow/ext_math/sqrt.php new file mode 100644 index 000000000..d918bfde4 --- /dev/null +++ b/hphp/test/slow/ext_math/sqrt.php @@ -0,0 +1,6 @@ +