Skip to content
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

Fix Concat operations with variables #953 #2

Merged
merged 5 commits into from
Nov 10, 2022
Merged

Fix Concat operations with variables #953 #2

merged 5 commits into from
Nov 10, 2022

Conversation

Slamdunk
Copy link

@Slamdunk Slamdunk commented Nov 8, 2022

@@ -485,10 +485,30 @@ public function unaryMinusNowdoc(): bool
{
return
-
(int)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no cast needed here too, and the type can be changed to int

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncaught TypeError: Unsupported operand types: string * int

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the typecast, it doesn't compile

@@ -165,6 +165,14 @@ private function getLines(NodeAbstract $node, bool $fromReturns): array
}

if ($node instanceof BinaryOp) {
if ($node instanceof BinaryOp\Concat &&
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is concat special vs. other binary operators line plus?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea, but it seems it is special.

I guess it is because it can trigger typecasting on object by a __toString() call, wether other binary ops don't

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your reasoning might make sense, but I still belive the var can be optimized to constant with opcache and thus var. itself should not generate a coverage line. I need to test.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to revert it, as it is unstable (line is not present in xdebug) when the var expr is known (from constatnt expr).

Copy link
Author

@Slamdunk Slamdunk Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to say, I'm kind of disappointed on how you are handling this contribution.

I created a valid test for a valid use case, I got the test passing, you found another edge case and istead of adding them to the tests, you throw my contribution away?

I'm losing my willingness to help, if you discard my help

Copy link
Owner

@mvorisek mvorisek Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry to hear that, I already spent about 2 - 3 MDs on static analyser to be really a minimal subset of xdebug and implementing sebastianbergmann#953 (comment) might take another several MDs. So what I was supposed to do?

instead of adding them to the tests

test is added in https://github.com/sebastianbergmann/php-code-coverage/blob/c4630fdec1def41d63ce7844d6e91ced5ccfa478/tests/_files/source_with_heavy_indentation.php#L95-L110 ($xa is non-const assign, $xb is const, not an uncommon case)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$var1 =
    'right'
    .
    $var1
;

$var1 =
    $var1
    .
    'left'
;

Where exactly are these two cases tested now in sebastianbergmann#949 ?

Copy link
Owner

@mvorisek mvorisek Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as of PHP 8.0) the variable assignments are covered

the concat const expr does not produce a coverage line if the variable is const expr - this is tested a for ex. in l105 in the example I posted - I also tested locally concat is not different than any other binary operator (like plus) in sense of coverage

<<<'EOF'
foo
foo
EOF
;
}

public function concatWithVar(): string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binary plus operator needs same test

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted, see #2 (comment)

@mvorisek mvorisek merged commit 7b6e0b5 into mvorisek:test_more_const_expr Nov 10, 2022
@Slamdunk Slamdunk deleted the fix_953 branch November 14, 2022 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants