Skip to content

-write produces syntax error in OCaml w.r.t. destructive substitution on module-items and tuple pattern-matching #187

Description

@ELLIOTTCABLE

Given this input (a destructive substitution of a module-item):

module Frequency : Wrap.S with type u := int = struct
  exception UnknownFrequency of int

  type t =
    | Daily
    | Monthly

  (* TODO: Right now billing only supports 3, 5, and 7. Fix this once billing is updated. *)
  let wrap = function
    | 1 -> Daily
    | 30 -> Monthly
    | n -> raise (UnknownFrequency n)

  let unwrap = function
    | Daily -> 1
    | Monthly -> 30
end

… Reanalyze v2.23.0 invoked with -write produces this (syntactically invalid, and also nonsensical in this case hahaha) output:

module Frequency : Wrap.S with type u := int [@@dead "Frequency.+unwrap"]  = struct
  exception UnknownFrequency of int

  type t =
    | Daily
    | Monthly

  (* TODO: Right now billing only supports 3, 5, and 7. Fix this once billing is updated. *)
  let wrap = function
    | 1 -> Daily
    | 30 -> Monthly
    | n -> raise (UnknownFrequency n) [@@dead "Frequency.+wrap"] 

  let unwrap = function
    | Daily -> 1
    | Monthly -> 30 [@@dead "Frequency.+unwrap"] 
end

Note that [@@dead "Frequency.+unwrap"] appears twice, in both the correct and nonsensical locations. A bug perhaps? (=


Similar issues when pattern-matching on a tuple:

let target, _group, filters = populate_mapping target group filters

... becomes ...

let target, _group [@@dead "Mappings.+_group"] , filters = populate_mapping target group filters

All told, -write dropped a few dozen syntax-errors across our codebase. Not the biggest deal, except I'm not sure how to correctly annotate these values so the next -write dosen't simply re-add them …

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions