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

Comments in match statement throw error #1956

Closed
mklein994 opened this issue Mar 25, 2022 · 4 comments
Closed

Comments in match statement throw error #1956

mklein994 opened this issue Mar 25, 2022 · 4 comments
Labels

Comments

@mklein994
Copy link

@prettier/plugin-php v0.18.3
Playground link

Input:

<?php

function fizzbuzz(int $i)
{
    print match (0) {
        /* this is a comment */
        $i % 15 => "fizzbuzz",
        $i % 3 => "fizz",
        $i % 5 => "buzz",
        default => $i,
    } . PHP_EOL;
}

Output:

Comment "/* this is a comment */" was not printed. Please report this error!

Of note, it doesn't matter what kind of comment, or where the comment is (end of line, before/after a pattern, etc.). Every scenario throws an exception.

@cseufert cseufert added the bug label Jun 3, 2022
@jaulz
Copy link

jaulz commented Jun 17, 2022

Yep, can confirm the same from my side.

@juandelperal
Copy link

Yep, same here

@villermen
Copy link

villermen commented Feb 1, 2023

While not ideal, I addressed this in the meantime by moving the comment to either before the entire statement or after one of the arrows:

<?php

function fizzbuzz(int $i)
{
    /* this is a comment */
    print match (0) {
        $i % 15 => "fizzbuzz",
        $i % 3 => "fizz",
        $i % 5 => /* this is another comment */ "buzz",
        default => $i,
    } . PHP_EOL;
}

That way Prettier won't fail on statements like these and you can still keep the comment fairly close to the desired statement.

@czosel
Copy link
Collaborator

czosel commented Aug 16, 2023

Fixed in v0.19.7 🎉

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

No branches or pull requests

6 participants