gccrs icon indicating copy to clipboard operation
gccrs copied to clipboard

grouped pattern is never identified

Open lucasly-ba opened this issue 1 month ago • 1 comments

code

pub fn a() {

   let int_reference = &3;
   match int_reference {
       &(0..=5) => (), /// will give us a range pattern
       _ => (),
   };

   let x = 0;
   match x {
        (3) => {}, /// will give us a literal pattern
        ((3)) => {}, /// likewise
        _ => {},
    };

}

lucasly-ba avatar Nov 20 '25 15:11 lucasly-ba

What do you mean by "never identified"? No warning for unnecessary parenthesis?

powerboat9 avatar Nov 20 '25 16:11 powerboat9

@lucasly-ba This is weird, i kind of simulated the same, it kind of did preserve the parenthesis

Image

match x { (3) => { }

AST is correctly identifying the GroupedPattern node (at least for the pretty printer)

Harishankar14 avatar Dec 18 '25 02:12 Harishankar14

What do you mean by "never identified"? No warning for unnecessary parenthesis?

@powerboat9 I guess the "identification" he meant is nothing but a creating a specific node in the tree that represents exactly what the user wrote.

Something like : You write (3).

Correct Behavior: the compiler creates a GroupedPattern node wrapping a LiteralPattern. It "remembers" you used brackets.

The Bug is that the compiler sees (3), ignores the brackets, and just creates a LiteralPattern (the number 3). It "forgets" you used brackets

But weird i haven't faced the issue

Harishankar14 avatar Dec 18 '25 02:12 Harishankar14

I kind of digged down a bit, and found that the Parser (AST): Actually does identify them, but the Lowering (HIR): Does not identify them (it throws them away).I think the issue title might be slightly misleading,the grouped pattern is identified initially by the parser (as seen in the AST), but it is lost during the transition to HIR. So it's not 'never identified,' but rather 'discarded during lowering.'

Harishankar14 avatar Dec 18 '25 02:12 Harishankar14

Yep, discarding of grouped patterns during lowering is intended (see #1783, blast from the past lol). Does it break anything?

powerboat9 avatar Dec 18 '25 23:12 powerboat9