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

Multiplication mutator should not mutate when return value is integer #1515

Merged

Conversation

sidz
Copy link
Member

@sidz sidz commented May 3, 2021

This PR fixes #1514 request.

composer.json Outdated
@@ -46,7 +46,7 @@
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"composer/xdebug-handler": "^1.3.3",
"composer/xdebug-handler": "^2.0",
Copy link
Member

Choose a reason for hiding this comment

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

seems like this commit should not be in this PR (already in master)

@@ -94,7 +96,19 @@ public function canMutate(Node $node): bool
return false;
}

return true;
$functionScope = $node->getAttribute(ReflectionVisitor::FUNCTION_SCOPE_KEY);
Copy link
Member

Choose a reason for hiding this comment

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

I believe we should also check that the current node is a return expression as it's done e.g. here: https://github.com/infection/infection/blob/master/src/Mutator/ReturnValue/This.php#L84

Otherwise, the following code will not be mutated, but it should:

public function mul(int $a, int $b): int
{
    $c = $a * $b;

    return 1;
}

btw, could you please add such case to tests so that we are sure it is mutated?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@maks-rafalko maks-rafalko added this to the 0.23.0 milestone May 3, 2021
@sidz sidz force-pushed the not-mutate-multiplication-mutate-returns-integer branch from 233ee09 to c9bb822 Compare May 5, 2021 20:15
Copy link
Member

@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

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

👌

@maks-rafalko maks-rafalko enabled auto-merge (rebase) May 5, 2021 20:19
@maks-rafalko maks-rafalko merged commit 0840e69 into master May 5, 2021
@maks-rafalko maks-rafalko deleted the not-mutate-multiplication-mutate-returns-integer branch May 5, 2021 20:26
@maks-rafalko
Copy link
Member

Thank you @sidz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiplication mutator should not mutate when return value is integer
2 participants