Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes phpstan/phpstan#6370 Closes phpstan/phpstan#4413
- Loading branch information
1 parent
7461185
commit 0917670
Showing
4 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Bug6370; | ||
|
||
interface I | ||
{ | ||
} | ||
class A implements I | ||
{ | ||
public function __construct(string $something) | ||
{ | ||
// one class needs a constructor to reproduce the issue | ||
unset($something); | ||
} | ||
} | ||
class B implements I | ||
{ | ||
} | ||
|
||
class Foo | ||
{ | ||
|
||
function test(string $className): I | ||
{ | ||
if (!in_array($className, [B::class, A::class], true)) { | ||
throw new \Exception(); | ||
} | ||
switch($className) { | ||
case A::class: | ||
return new $className('something'); | ||
case B::class: | ||
return new $className(); | ||
default: | ||
throw new \Exception(); | ||
} | ||
} | ||
|
||
function test2(string $className): I | ||
{ | ||
if (!in_array($className, [B::class, A::class], true)) { | ||
throw new \Exception(); | ||
} | ||
switch($className) { | ||
case A::class: | ||
return new $className(1); | ||
case B::class: | ||
return new $className(); | ||
default: | ||
throw new \Exception(); | ||
} | ||
} | ||
|
||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Bug4413; | ||
|
||
use DateTime; | ||
|
||
/** | ||
* @param class-string<DateTime> $date | ||
*/ | ||
function takesDate(string $date): void {} | ||
|
||
function input(string $in): void { | ||
switch ($in) { | ||
case DateTime::class : | ||
takesDate($in); | ||
break; | ||
case \stdClass::class : | ||
takesDate($in); | ||
break; | ||
} | ||
} |