-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed checkExplicitMixed with TemplateMixedType
- Loading branch information
1 parent
b4f81db
commit 6ba9ef2
Showing
7 changed files
with
162 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Generic; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use PHPStan\Type\MixedType; | ||
use PHPStan\Type\StrictMixedType; | ||
use PHPStan\Type\Type; | ||
|
||
/** @api */ | ||
final class TemplateStrictMixedType extends StrictMixedType implements TemplateType | ||
{ | ||
|
||
/** @use TemplateTypeTrait<StrictMixedType> */ | ||
use TemplateTypeTrait; | ||
|
||
public function __construct( | ||
TemplateTypeScope $scope, | ||
TemplateTypeStrategy $templateTypeStrategy, | ||
TemplateTypeVariance $templateTypeVariance, | ||
string $name, | ||
StrictMixedType $bound | ||
) | ||
{ | ||
$this->scope = $scope; | ||
$this->strategy = $templateTypeStrategy; | ||
$this->variance = $templateTypeVariance; | ||
$this->name = $name; | ||
$this->bound = $bound; | ||
} | ||
|
||
public function isSuperTypeOfMixed(MixedType $type): TrinaryLogic | ||
{ | ||
return $this->isSuperTypeOf($type); | ||
} | ||
|
||
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic | ||
{ | ||
return $this->isSubTypeOf($acceptingType); | ||
} | ||
|
||
public function traverse(callable $cb): Type | ||
{ | ||
$newBound = $cb($this->getBound()); | ||
if ($this->getBound() !== $newBound && $newBound instanceof MixedType) { | ||
return new self( | ||
$this->scope, | ||
$this->strategy, | ||
$this->variance, | ||
$this->name, | ||
$newBound | ||
); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Bug3566; | ||
|
||
class HelloWorld | ||
{ | ||
|
||
/** | ||
* @phpstan-template TMemberType | ||
* @phpstan-param array<mixed, TMemberType> $array | ||
* @phpstan-param \Closure(TMemberType) : void $validator | ||
*/ | ||
public static function validateArrayValueType(array $array, \Closure $validator) : void{ | ||
foreach($array as $k => $v){ | ||
try{ | ||
$validator($v); | ||
}catch(\TypeError $e){ | ||
throw new \TypeError("Incorrect type of element at \"$k\": " . $e->getMessage(), 0, $e); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @phpstan-template TMemberType | ||
* @phpstan-param TMemberType $t | ||
* @phpstan-param \Closure(int) : void $validator | ||
*/ | ||
public static function doFoo($t, \Closure $validator) : void{ | ||
$validator($t); | ||
} | ||
|
||
/** | ||
* @phpstan-template TMemberType | ||
* @phpstan-param TMemberType $t | ||
* @phpstan-param \Closure(mixed) : void $validator | ||
*/ | ||
public static function doFoo2($t, \Closure $validator) : void{ | ||
$validator($t); | ||
} | ||
} |
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