Semantic Diff

#9127 Keep the comments around a list pattern's only spread when formatting

1 commit

6ea63e5a9114711e68d92f0eb4b355848a8fd337..pr-9127

939f26b13 · cknitt + Claude · Oct 29, 2026, 17:59 UTC

Keep the comments around a list pattern's only spread when formatting

Why

list{...r} parses to the pattern r itself, but the parser gave that pattern the location of the whole list{...}. A comment around the spread was then inside the location of the leaf r, where comment attachment leaves it unattached, so formatting dropped it. The pattern now keeps the location of r, like list{...e} in expressions, and the comments become leading or trailing comments of r.

modifiedFormat comment around a list pattern's only spread

let f = x =>  switch x {  | list{/* d */ ...r} => r  }let g = (list{...r /* t */}) => r
rescript
Before
After
let f = x =>let f = x => switch x { switch x { | r => r /* d */ | r => r } }let g = r => rlet g = r /* t */ => r

Fixes: #9123

Review

  • Why is the comment printed before |? That is where the formatter already puts a leading comment of a case pattern, as for | /* d */ r.