plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Comments in match statement throw error

Open mklein994 opened this issue 3 years ago • 2 comments

@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.

mklein994 avatar Mar 25 '22 20:03 mklein994

Yep, can confirm the same from my side.

jaulz avatar Jun 17 '22 15:06 jaulz

Yep, same here

juandelperal avatar Aug 23 '22 08:08 juandelperal

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.

villermen avatar Feb 01 '23 13:02 villermen

Fixed in v0.19.7 :tada:

czosel avatar Aug 16 '23 07:08 czosel