-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[W.I.P.] Fix implicit to and from bool type juggling #60890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.4
Are you sure you want to change the base?
Conversation
Hey! To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
@@ -568,7 +568,7 @@ private function parseDefinition(string $id, array|string|null $service, string | |||
if (isset($call['method']) && \is_string($call['method'])) { | |||
$method = $call['method']; | |||
$args = $call['arguments'] ?? []; | |||
$returnsClone = $call['returns_clone'] ?? false; | |||
$returnsClone = $call['returns_clone'] ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will break if returns_clone
is not defined in the array.
and that's a case where we expect a boolean if the key is defined, or an undefined key (which should then default to false
)
@@ -307,7 +307,7 @@ public function setMethodCalls(array $calls = []): static | |||
{ | |||
$this->calls = []; | |||
foreach ($calls as $call) { | |||
$this->addMethodCall($call[0], $call[1], $call[2] ?? false); | |||
$this->addMethodCall($call[0], $call[1], $call[2] ? true : false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a case where the third value in the array is expected to be a boolean or absent, which is broken in this change.
$definition->addMethodCall( | ||
$call->getAttribute('method'), | ||
$this->getArgumentsAsPhp($call, 'argument', $file), | ||
(bool) XmlUtils::phpize($call->getAttribute('returns-clone')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest doing a method handling of the case of the missing attribute (instead of handling it as $call->getAttribute('returns-clone')
returning an empty string which then casts to false
)
@@ -589,7 +589,7 @@ private function parseDefinition(string $id, array|string|null $service, string | |||
} else { | |||
$method = $call[0]; | |||
$args = $call[1] ?? []; | |||
$returnsClone = $call[2] ?? false; | |||
$returnsClone = $call[2] ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the existing code should probably be kept here as well.
@@ -402,7 +402,7 @@ public function handleError(int $type, string $message, string $file, int $line) | |||
|
|||
// Never throw on warnings triggered by assert() | |||
if (\E_WARNING === $type && 'a' === $message[0] && 0 === strncmp($message, 'assert(): ', 10)) { | |||
$throw = 0; | |||
$throw = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$throw
is still an int if we don't enter this if
branch, as it is defined with bitwise comparisons on line 400. It needs to be fixed there as well.
Some of those changes are definitely legitimate as they are clearly mistakes in the existing code that went unnoticed (static analysis could catch them, but our CI only reports new violations in each PR and we never worked on fixing issues reported in existing code):
Those could definitely be submitted directly (against the 6.4 branch). We have other cases (when using preg_match or bitwise comparisons) where we indeed rely on the implicit type juggling of the return type, which are legitimate changes once PHP deprecates those type juggling rules (static analysis probably also prevents them for new code). As reported in my review comments, the changes done in the DI component look wrong to me (and are the cause of failures in the CI as well) |
Yes I had figured out the cause, but I was having some other local failures before that made it difficult to waddle through stuff. There is also a bug in master on php-src which is not helping me to get a good overview of the situation. Question about |
d89795e
to
b812e26
Compare
@@ -336,7 +336,7 @@ public function testProcessFailsOnPassingClassToScalarTypedParameter() | |||
(new CheckTypeDeclarationsPass(true))->process($container); | |||
} | |||
|
|||
public function testProcessSuccessOnPassingBadScalarType() | |||
public function xtestProcessSuccessOnPassingBadScalarType() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why skipping this test ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stole this from @nicolas-grekas WIP commit: nicolas-grekas@02e3881
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈
@@ -51,7 +51,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void | |||
$container->register(StaticExtensionWithAttributes::class, StaticExtensionWithAttributes::class) | |||
->setAutoconfigured(true); | |||
$container->register(RuntimeExtensionWithAttributes::class, RuntimeExtensionWithAttributes::class) | |||
->setArguments(['prefix_']) | |||
->setArguments([true]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that RuntimeExtensionWithAttributes
performs string concatenation with the prefix, the right fix is rather to change the constructor argument type in this RuntimeExtensionWithAttributes stub class.
@@ -76,7 +76,8 @@ final public static function isStringable(mixed $value): bool | |||
*/ | |||
final public static function resolve(\Stringable|string|int|float|bool $value): string | |||
{ | |||
return $value; | |||
// TODO Do something more useful for false and true? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the TODO should be removed, as a string cast is also what we do in fromStringable
Not sure what those asserts are doing however
There is no need to test false as this is a PHP engine behaviour to cast to empty string
There is no need to test false as this is a PHP engine behaviour to cast to empty string
b812e26
to
a249be4
Compare
This is to see part of the impact of php/php-src#18879, and it seems to be finding some bugs in tests or SF itself, but I would need confirmation from other people.
This is very much W.I.P. and I might use CI to check that my changes are correct as I have some local test failures even just running with 8.4.8
I am well aware the commit messages are kinda useless at the moment, but they are somewhat self-contained, so they can be looked at individually.