let-def / lrgrep

Menhir polishing toolbox, for experienced druids
25 stars 2 forks source link

Generate separate pattern arms for each symbol #11

Closed SquidDev closed 10 months ago

SquidDev commented 10 months ago

When multiple symbols may match, we generate code like:

let x = match Parser_raw.MenhirInterpreter.incoming_symbol st with
| T T_LPAREN | T T_RPAREN -> (x : unit)
| _ -> assert false

However, or patterns don't introduce a constraint on the GADT's type variable, so this code fails to compile. Instead, we need to generate a separate arm for each case:

let x = match Parser_raw.MenhirInterpreter.incoming_symbol st with
| T T_LPAREN -> (x : unit)
| T T_RPAREN -> (x : unit)
| _ -> assert false
let-def commented 10 months ago

Nice catch, thank you for the fix!