Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,261
    • Issues 5,261
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 567
    • Merge requests 567
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17359
Closed
Open
Issue created Oct 14, 2019 by Xia Li-yao@LysxiaContributor

Layout rules: missing implicit semicolon after `if`

Summary

The following program is accepted by GHC, where the condition True starts at the same column as the do-block:

-- GHC accepts, but this looks BAD according to the standard
main = do
  if
  True then print () else print ()

For comparison, the following variants aren't accepted, where instead we try to do the same thing with either of the then or else branches:

-- BAD, and GHC rightly rejects it
main = do
  if True then
  print () else print ()

-- BAD, and GHC rightly rejects it
main = do
  if True then print () else
  print ()

Reading Lexer.x, it might be that the logic around MultiWayIf layout is silencing the implicit semicolon insertion, but I'm not entirely sure.

Link to the relevant section of Haskell 2010 (the layout algorithm): https://www.haskell.org/onlinereport/haskell2010/haskellch10.html#x17-17500010.3

Is that actually valid? Or is this a known bug? (I couldn't find any mention of it in a cursory search.)

Environment

  • GHC version used: GHC 8.6. Read the code on master.
Edited Oct 15, 2019 by Xia Li-yao
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking