reasonml / reasonml/reason

unexpected if/else behavior (expected braces to be required)

Open
#1,604 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

KIND: FEATURE REQUEST Parser
Dominant language
OCaml
Stars
10.3k
Forks
438
PR merge metrics
No merged PRs in 30d

Description

I expected this:

let x = if (true) {
  10
} else {
  5
} |> (a) => a + 2;

to be equivalent to this:

let x = (if (true) {
  10
} else {
  5
}) |> (a) => a + 2;

when in fact the pipe was counted as part of the else

let x = if (true) {
  10
} else ({
  5
} |> (a) => a + 2);

Can we make if/else require braces? b/c we have ternary for the "short and sweet" version.
(might this also enable paren-less if condition?)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two if/else examples from the issue and confirming how the pipe is parsed without parentheses. Then investigate the language's syntax and parser behavior to determine whether braces should be required and whether parenthesis-free conditions are compatible. Done means the intended syntax rules are agreed and the behavior is covered by appropriate parser or language tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.