haskell / haskell/cabal

Properly implement round-trip property for `if`/`else`

Open
#6,193 1 comment 0 reactions 0 assignees View on GitHub
Cabal: parser exact-print
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

In https://github.com/haskell/cabal/pull/6188, @phadej is hesitating to delete dead code because

> That dead code reminds me of an unsolved issue, but when it's gone there won't be anything reminding of that ugliness...

So I'm recording his process in https://github.com/haskell/cabal/pull/6188#issuecomment-520177808 here so that this issue can serve as a memory hook for him to come back and fix the code later

----

The code there is in the state to have roundtrip property for code like

```
if flag(some-condition)
buildable: True
else
buildable: False
```

which is ugly when pretty-printed as:

```
if flag(some-condition)
else
buildable: False
```

That's because buildable: True is no-op, and there could be other a like.

One way, is to pretty-print that as

```
if !flag(some-condition)
buildable: False
```

But that violates roundtrip property.

Contributor guide

Open the contributing guide

Research direction

Start with the code and discussion referenced in pull request #6188, especially the handling of if/else blocks and pretty-printing. Reproduce the shown buildable example and inspect how parsing and printing affect its round-trip property. Done means the representation is pretty-printed without losing that property, with the intended behavior clarified for no-op branches.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
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.