Skip to content

Conversation

@klwuco
Copy link

@klwuco klwuco commented Dec 22, 2025

Allow inherited attributes to inline type annotations inside the production rule.

(* The definition of the variable is local to the rule. *)
(* This is merely an artifact from parsing, and is meant to be syntax sugar that wil
be translated to the appropriate regular ProdRule and TypeAnnotation after parsing. *)
| InlinedTypeProdRule of string * (string * il_type) list * prod_rule_rhs list * Lexing.position
Copy link
Owner

@lorchrob lorchrob Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding another constructor for InlinedTypeProdRule, just change the type of the ProdRule constructor to ProdRule of string * (string * il_type) list * prod_rule_rhs list * Lexing.position. Then later you do not need to add all the cases of | InlinedTypeProdRule _ -> assert false. In most cases we do not need the extra type information, so we can do something like this

| InlinedTypeProdRule (nt, ias, rhss, _) ->    
  let ias = List.map fst ias in 
  ...
  <original code here>

But this way, the type information is there when it is needed in desugarLocalVars.ml

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: When updating ProdRule, we are essentially requiring type annotations. So at parse time, we will not support LHS of the form <nt>(ia) ::= ... without the type annotation, so that rule will have to be removed.

ast
in

(* Desugar local variables *)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious -- why did you put it here in the pipeline rather than directly before the desugar_attributes step?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants