Skip to content

Commit

Permalink
Fix #2952 - always be cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 9, 2020
1 parent 2a72990 commit 0cfe565
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ private static function fleshOutAtomicType(
if ($return_type instanceof Type\Atomic\TClassString
&& $return_type->as_type
) {
$new_as_type = $return_type->as_type;
$new_as_type = clone $return_type->as_type;

self::fleshOutAtomicType(
$codebase,
Expand Down
33 changes: 33 additions & 0 deletions tests/ClassStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,39 @@ public static function r() : string
}
}'
],
'traitClassStringClone' => [
'<?php
trait Factory
{
/** @return class-string<static> */
public static function getFactoryClass()
{
return static::class;
}
}
class A
{
use Factory;
public static function factory(): self
{
$class = static::getFactoryClass();
return new $class;
}
}
class B
{
use Factory;
public static function factory(): self
{
$class = static::getFactoryClass();
return new $class;
}
}'
],
];
}

Expand Down

0 comments on commit 0cfe565

Please sign in to comment.