-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4700 from TysonAndre/disjunctive-normal-form-pr
Support parsing php 8.2 disjunctive normal form type
- Loading branch information
Showing
7 changed files
with
59 additions
and
2 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
7 changes: 7 additions & 0 deletions
7
tests/php82_files/expected/004_disjunctive_normal_form_param.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%s:4 PhanPluginUnknownMethodReturnType Method \NS4\A::example() has no declared or inferred return type | ||
%s:12 PhanDebugAnnotation @phan-debug-var requested for variable $param - it has union type (\NS4\B&\NS4\C)|\NS4\A(real=(\NS4\B&\NS4\C)|\NS4\A) | ||
%s:14 PhanParamTooMany Call with 1 arg(s) to \NS4\A::example() which only takes 0 arg(s) defined at %s:4 | ||
%s:16 PhanTypeMismatchReturnSuperType Returning new B() of type \NS4\B but example() is declared to return (\NS4\B&\NS4\C)|\NS4\A (saw a supertype instead of a subtype) | ||
%s:21 PhanTypeMismatchArgumentSuperType Argument 1 ($param) is new B() of type \NS4\B but \NS4\example() takes (\NS4\B&\NS4\C)|\NS4\A defined at %s:12 (expected type to be the same or a subtype, but saw a supertype instead) | ||
%s:23 PhanTypeMismatchArgument Argument 1 ($param) is new \stdClass() of type \stdClass but \NS4\example() takes (\NS4\B&\NS4\C)|\NS4\A defined at %s:12 | ||
%s:24 PhanTypeMismatchArgumentReal Argument 1 ($param) is null of type null but \NS4\example() takes (\NS4\B&\NS4\C)|\NS4\A defined at %s:12 |
2 changes: 2 additions & 0 deletions
2
tests/php82_files/expected/005_dnf_type_property.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
%s:14 PhanTypeMismatchPropertyReal Assigning null of type null to property but \X5->value is (\Countable&\ArrayAccess)|\stdClass | ||
%s:16 PhanTypeMismatchPropertyReal Assigning $v2 of type \X5 to property but \X5->value is (\Countable&\ArrayAccess)|\stdClass |
24 changes: 24 additions & 0 deletions
24
tests/php82_files/src/004_disjunctive_normal_form_param.php
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,24 @@ | ||
<?php | ||
namespace NS4; | ||
class A { | ||
public function example() { | ||
echo "done\n"; | ||
} | ||
} | ||
class B { | ||
} | ||
interface C {} | ||
class D extends B implements C {} | ||
function example(A|(B&C) $param): A|(B&C) { | ||
'@phan-debug-var $param'; | ||
$param->example('extra'); | ||
if (random_int(0,1)) { | ||
return new B(); | ||
} | ||
return $param; | ||
} | ||
example(new A()); // valid | ||
example(new B()); // invalid | ||
example(new D()); // valid | ||
example(new \stdClass()); // invalid | ||
example(null); // invalid |
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,16 @@ | ||
<?php | ||
class X5 { | ||
public stdClass|(Countable&ArrayAccess) $value; | ||
} | ||
class C5 implements Countable { | ||
public function count() { | ||
return 0; | ||
} | ||
} | ||
$v = new X5(); | ||
$v2 = new X5(); | ||
$v->value = new C5(); // TODO: This should warn | ||
$v2->value = new ArrayObject(); | ||
$v->value = null; | ||
$v->value = $v2->value; | ||
$v->value = $v2; |