Fix type inference for ZendParamMode

Parameters of ZendParamMode functions aren't converted to the
destination type, so don't try to apply a type.
Esse commit está contido em:
mwilliams
2013-07-24 13:25:55 -07:00
commit de Sara Golemon
commit cd5e74ec7e
5 arquivos alterados com 20 adições e 4 exclusões
+8 -3
Ver Arquivo
@@ -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);
+1
Ver Arquivo
@@ -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;
+2 -1
Ver Arquivo
@@ -788,7 +788,8 @@
"name": "sqrt",
"desc": "Returns the square root of arg.",
"flags": [
"HasDocComment"
"HasDocComment",
"ZendParamMode"
],
"return": {
"type": "Double",
+6
Ver Arquivo
@@ -0,0 +1,6 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
var_dump(sqrt('foo'));
var_dump(sqrt('16'));
var_dump(sqrt(array()));
+3
Ver Arquivo
@@ -0,0 +1,3 @@
NULL
float(4)
NULL