Changeset View
Changeset View
Standalone View
Standalone View
duchain/helper.cpp
Show First 20 Lines • Show All 476 Lines • ▼ Show 20 Line(s) | 429 | { | |||
---|---|---|---|---|---|
477 | return type; | 477 | return type; | ||
478 | } | 478 | } | ||
479 | 479 | | |||
480 | AbstractType::Ptr parameterType(const ParameterAst* node, AbstractType::Ptr phpDocTypehint, EditorIntegrator* editor, DUContext* currentContext) | 480 | AbstractType::Ptr parameterType(const ParameterAst* node, AbstractType::Ptr phpDocTypehint, EditorIntegrator* editor, DUContext* currentContext) | ||
481 | { | 481 | { | ||
482 | AbstractType::Ptr type; | 482 | AbstractType::Ptr type; | ||
483 | if (node->parameterType) { | 483 | if (node->parameterType) { | ||
484 | type = determineTypehint(node->parameterType, editor, currentContext); | 484 | type = determineTypehint(node->parameterType, editor, currentContext); | ||
485 | } else if (node->defaultValue) { | 485 | } | ||
486 | if (node->defaultValue) { | ||||
486 | ExpressionVisitor v(editor); | 487 | ExpressionVisitor v(editor); | ||
487 | node->defaultValue->ducontext = currentContext; | 488 | node->defaultValue->ducontext = currentContext; | ||
488 | v.visitNode(node->defaultValue); | 489 | v.visitNode(node->defaultValue); | ||
489 | type = v.result().type(); | 490 | AbstractType::Ptr defaultValueType = v.result().type(); | ||
491 | | ||||
492 | /* | ||||
493 | * If a typehint is already set, default values can only be the same type or `null` in PHP | ||||
494 | * If it's the same type, the type is already correctly set, | ||||
495 | * so we can ignore this case. | ||||
496 | * If it's null (which cannot be a typehint), add it as UnsureType | ||||
497 | */ | ||||
498 | if (type && defaultValueType.cast<IntegralType>() && defaultValueType.cast<IntegralType>()->dataType() == IntegralType::TypeNull) { | ||||
499 | if (type.cast<UnsureType>()) { | ||||
500 | UnsureType::Ptr unsure = type.cast<UnsureType>(); | ||||
501 | AbstractType::Ptr nullType = AbstractType::Ptr(new IntegralType(IntegralType::TypeNull)); | ||||
502 | unsure->addType(defaultValueType->indexed()); | ||||
503 | } else { | ||||
504 | UnsureType::Ptr unsure(new UnsureType()); | ||||
505 | unsure->addType(type->indexed()); | ||||
506 | unsure->addType(defaultValueType->indexed()); | ||||
507 | | ||||
508 | type = AbstractType::Ptr(unsure); | ||||
509 | } | ||||
510 | } else { | ||||
511 | //Otherwise, let the default value dictate the parameter type | ||||
512 | type = defaultValueType; | ||||
513 | } | ||||
490 | } | 514 | } | ||
491 | if (!type) { | 515 | if (!type) { | ||
492 | if (phpDocTypehint) { | 516 | if (phpDocTypehint) { | ||
493 | type = phpDocTypehint; | 517 | type = phpDocTypehint; | ||
494 | } else { | 518 | } else { | ||
495 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeMixed)); | 519 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeMixed)); | ||
496 | } | 520 | } | ||
497 | } | 521 | } | ||
Show All 36 Lines |