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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -788,7 +788,8 @@
|
||||
"name": "sqrt",
|
||||
"desc": "Returns the square root of arg.",
|
||||
"flags": [
|
||||
"HasDocComment"
|
||||
"HasDocComment",
|
||||
"ZendParamMode"
|
||||
],
|
||||
"return": {
|
||||
"type": "Double",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
var_dump(sqrt('foo'));
|
||||
var_dump(sqrt('16'));
|
||||
var_dump(sqrt(array()));
|
||||
@@ -0,0 +1,3 @@
|
||||
NULL
|
||||
float(4)
|
||||
NULL
|
||||
Referência em uma Nova Issue
Bloquear um usuário