Changeset View
Changeset View
Standalone View
Standalone View
duchain/expressionvisitor.cpp
Show First 20 Lines • Show All 213 Lines • ▼ Show 20 Line(s) | |||||
214 | 214 | | |||
215 | void ExpressionVisitor::visitClosure(ClosureAst* node) | 215 | void ExpressionVisitor::visitClosure(ClosureAst* node) | ||
216 | { | 216 | { | ||
217 | FunctionType* closureType = new FunctionType; | 217 | FunctionType* closureType = new FunctionType; | ||
218 | m_result.setType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | 218 | m_result.setType(AbstractType::Ptr(new IntegralType(IntegralType::TypeVoid))); | ||
219 | if (node->functionBody) { | 219 | if (node->functionBody) { | ||
220 | visitInnerStatementList(node->functionBody); | 220 | visitInnerStatementList(node->functionBody); | ||
221 | } | 221 | } | ||
222 | closureType->setReturnType(m_result.type()); | 222 | | ||
223 | //First try return typehint or phpdoc return typehint | ||||
224 | AbstractType::Ptr type = returnType(node->returnType, {}, m_editor, m_currentContext); | ||||
225 | if (!type) { | ||||
226 | //If failed, use the inferred type from return statements | ||||
227 | type = m_result.type(); | ||||
228 | } | ||||
229 | closureType->setReturnType(type); | ||||
223 | 230 | | |||
224 | if (node->parameters->parametersSequence) { | 231 | if (node->parameters->parametersSequence) { | ||
225 | const KDevPG::ListNode< ParameterAst* >* it = node->parameters->parametersSequence->front(); | 232 | const KDevPG::ListNode< ParameterAst* >* it = node->parameters->parametersSequence->front(); | ||
226 | forever { | 233 | forever { | ||
227 | AbstractType::Ptr type = parameterType(it->element, {}, m_editor, m_currentContext); | 234 | AbstractType::Ptr type = parameterType(it->element, {}, m_editor, m_currentContext); | ||
228 | closureType->addArgument(type); | 235 | closureType->addArgument(type); | ||
229 | if ( it->hasNext() ) { | 236 | if ( it->hasNext() ) { | ||
230 | it = it->next; | 237 | it = it->next; | ||
▲ Show 20 Lines • Show All 562 Lines • Show Last 20 Lines |