forked from phan/phan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP(broken) -
mixed
should be treated as nullable
- Work on fixing the false positives during redundant condition detection - Add a separate `non-null-mixed` type - TODO: Avoid regressions in inferred phpdoc type for array access - TODO: Continue to infer phpdoc `?mixed` type with a `?` in issue messages when combining mixed with null or converting mixed to nullable. (and emit PhanTypeArraySuspiciousNullable) For phan#4276
- Loading branch information
1 parent
850a302
commit 38beaab
Showing
15 changed files
with
176 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phan\Language\Type; | ||
|
||
use Phan\CodeBase; | ||
use Phan\Language\Context; | ||
use Phan\Language\Type; | ||
|
||
/** | ||
* Represents the PHPDoc `non-empty-mixed` type, which can cast to/from any non-null type and is non-null | ||
* | ||
* For purposes of analysis, there's usually no difference between mixed and nullable mixed. | ||
* @phan-pure | ||
*/ | ||
final class NonNullMixedType extends MixedType | ||
{ | ||
/** @phan-override */ | ||
public const NAME = 'non-null-mixed'; | ||
|
||
public static function instance(bool $is_nullable) | ||
{ | ||
if ($is_nullable) { | ||
return MixedType::instance(true); | ||
} | ||
static $instance = null; | ||
return $instance ?? ($instance = static::make('\\', self::NAME, [], false, Type::FROM_NODE)); | ||
} | ||
|
||
public function canCastToType(Type $type): bool | ||
{ | ||
return !($type instanceof NullType || $type instanceof VoidType); | ||
} | ||
|
||
/** | ||
* @param Type[] $target_type_set 1 or more types @phan-unused-param | ||
* @override | ||
*/ | ||
public function canCastToAnyTypeInSet(array $target_type_set): bool | ||
{ | ||
foreach ($target_type_set as $t) { | ||
if ($this->canCastToType($t)) { | ||
return true; | ||
} | ||
} | ||
return (bool)$target_type_set; | ||
} | ||
|
||
public function asGenericArrayType(int $key_type): Type | ||
{ | ||
return GenericArrayType::fromElementType($this, false, $key_type); | ||
} | ||
|
||
/** | ||
* @unused-param $code_base | ||
* @unused-param $context | ||
*/ | ||
public function canCastToDeclaredType(CodeBase $code_base, Context $context, Type $other): bool | ||
{ | ||
return $this->canCastToType($other); | ||
} | ||
|
||
public function asObjectType(): ?Type | ||
{ | ||
return ObjectType::instance(false); | ||
} | ||
|
||
public function asArrayType(): ?Type | ||
{ | ||
return NonEmptyGenericArrayType::fromElementType( | ||
MixedType::instance(false), | ||
false, | ||
GenericArrayType::KEY_MIXED | ||
); | ||
} | ||
|
||
public function asNonFalseyType(): Type | ||
{ | ||
return $this; | ||
} | ||
|
||
/** @override */ | ||
public function isNullable(): bool | ||
{ | ||
return $this->is_nullable; | ||
} | ||
|
||
/** @override */ | ||
public function __toString(): string | ||
{ | ||
return $this->is_nullable ? '?non-null-mixed' : 'non-null-mixed'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
%s:11 PhanTypeMismatchArgumentInternal%SReal Argument 1 ($value) is $x of type string but \count() takes \Countable|\ResourceBundle|\SimpleXMLElement|array%S | ||
%s:14 PhanTypeMismatchArgumentInternal Argument 1 ($value) is $y of type string but \count() takes \Countable|\ResourceBundle|\SimpleXMLElement|array | ||
%s:9 PhanDebugAnnotation @phan-debug-var requested for variable $x - it has union type array|string | ||
%s:11 PhanDebugAnnotation @phan-debug-var requested for variable $x - it has union type string(real=string) | ||
%s:13 PhanTypeMismatchArgumentInternalReal Argument 1 ($value) is $x of type string but \count() takes \Countable|\ResourceBundle|\SimpleXMLElement|array (real type \Countable|array) | ||
%s:16 PhanTypeMismatchArgumentInternal Argument 1 ($value) is $y of type string but \count() takes \Countable|\ResourceBundle|\SimpleXMLElement|array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
tests/php80_files/expected/025_named_arg_callable_missing.php.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters