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

Incorrect behavior of DowngradeMatchToSwitchRector + DowngradeThrowExprRector #6750

Closed
leoloso opened this issue Oct 18, 2021 · 0 comments · Fixed by rectorphp/rector-src#1019
Labels

Comments

@leoloso
Copy link
Contributor

leoloso commented Oct 18, 2021

Bug Report

Subject Details
Rector version last dev-master
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.org/demo/1ec2fda5-2490-6c56-9d12-93cf2aafeb8a

When there's a throw new Exception in the match, like here:

<?php

final class DemoFile
{
    public function run($param)
    {
        return match ($param) {
            'a' => 'hi',
            'b' => 'bye',
            default => throw new Exception('no salutation'),
        };
    }
}

The downgraded switch should not add a return to throw new Exception

Responsible rules

  • DowngradeMatchToSwitchRector
  • DowngradeThrowExprRector

Expected Behavior

public function run($param)
{
    switch ($param) {
        case 'a':
            return 'hi';
        case 'b':
            return 'bye';
        default:
-            return throw new Exception('no salutation');
+            throw new Exception('no salutation');
    }
}
@leoloso leoloso added the bug label Oct 18, 2021
samsonasik added a commit to rectorphp/rector-src that referenced this issue Oct 18, 2021
TomasVotruba pushed a commit to rectorphp/rector-src that referenced this issue Oct 18, 2021
…or (#1019)

* Add failing test fixture for DowngradeMatchToSwitchRector + DowngradeThrowExprRector

# Failing Test for DowngradeMatchToSwitchRector + DowngradeThrowExprRector

Based on https://getrector.org/demo/1ec2fda5-2490-6c56-9d12-93cf2aafeb8a

* update fixture

* Closes #1018 Fixes rectorphp/rector#6750

* [ci-review] Rector Rectify

Co-authored-by: Leonardo Losoviz <leo@getpop.org>
Co-authored-by: GitHub Action <action@github.com>
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 a pull request may close this issue.

1 participant