replace VarExportFunctionDynamicReturnTypeExtension with conditional-type stub#1244
replace VarExportFunctionDynamicReturnTypeExtension with conditional-type stub#1244staabm wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
this stub is taken 1:1 from psalm, to verify phpstan is kind of compatible with the psalm notations
There was a problem hiding this comment.
when running tests on phpstan-src@1.6.x it seems to make a difference whether the @return expression here is sorrounded by braces.. I think this is not expected
see
vs. (when running without braces)
(both results are not correct though ;))
There was a problem hiding this comment.
after reading the 1.6.x release blog post, I conclude the paranthesis are necessary.
9fbc45e to
ce13ef2
Compare
staabm
left a comment
There was a problem hiding this comment.
I don't know why yet, but the result of the test actually look like
9) PHPStan\Analyser\NodeScopeResolverTest::testFileAsserts with data set "C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser/data/pr-1244.php:24" ('type', 'C:\dvl\Workspace\phpstan-src-...44.php', PHPStan\Type\Constant\ConstantStringType Object (...), PHPStan\Type\ConditionalTypeForParameter Object (...), 24)
Expected type string|true, got type ($return is true ? string : true) in C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser/data/pr-1244.php on line 24.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'string|true'
+'($return is true ? string : true)'
C:\dvl\Workspace\phpstan-src-staabm\src\Testing\TypeInferenceTestCase.php:90
C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser\NodeScopeResolverTest.php:919
10) PHPStan\Analyser\NodeScopeResolverTest::testFileAsserts with data set "C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser/data/pr-1244.php:25" ('type', 'C:\dvl\Workspace\phpstan-src-...44.php', PHPStan\Type\Constant\ConstantStringType Object (...), PHPStan\Type\ConditionalTypeForParameter Object (...), 25)
Expected type true, got type ($return is true ? string : true) in C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser/data/pr-1244.php on line 25.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'true'
+'($return is true ? string : true)'
I tried moving the test into a NodeScopeResolverTest but this did not make a difference compared to LegacyNodeScopeResolverTest.
it seems the return-type is not finally resolved.
not sure whether I am missing something in the stub-file, or whether I am hitting a bug within conditional-types, which make phpstan not resolve the ConditionalTypeForParameter.
any hint would be appreciated
There was a problem hiding this comment.
psalm supports a @return ($return is true ? string : void) type, while it seems in phpstan atm we need to explicitly use null
There was a problem hiding this comment.
This is because the function map specifies var_export to return string|null which isn't compatible with string|void.
|
I'll try to look into this tomorrow. |
db79a65 to
dc3ae18
Compare
|
So the big problem is that default values aren't exposed for native functions, so |
|
thank you for your support Richard <3. |
|
Finished and merged: 09635a1 Thank you! |


with this PR I want to try to replace a existing phpstan extension with stubs and conditional types.
I did so with some very basic examples, like
var_exportetc. as a proof-of-concept.It does not work yet though.