Skip to content

Handling or-patterns with exceptions in match%lwt #1125

Description

@Halbaroth

The following code is rejected:

match%lwt foo with
| exception Bar | None -> baz ()
| Some _ -> babar ()

with the error:

Exception patterns are not allowed in this position

The ppx produces the following code:

Lwt.try_bind 
  (fun () -> foo)
  (function 
    | exception Bar | None -> baz ()
    | Some _ -> barbar ())
   (function | exn -> Lwt.reraise exn)

You may generate the following code?

Lwt.try_find
  (fun () -> foo)
  (function 
    | None -> baz ()
    | Some _ -> barbar ())
  (function
    | exception Bar -> baz () 
    | exn -> Lwt.reraise exn)

I'm not sure it's correct to duplicate the branch ;)

Activity

  1. raphael-proust commented on Sep 21, 2026

    @raphael-proust
    Collaborator

    hmm i'll have to think about that

    i don't think it's a problem to duplicate the branch. could interfere with other ppxes maybe but that'd be pretty wild.

    i'll ask around too

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