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,255
    • Issues 5,255
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 563
    • Merge requests 563
  • 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
  • #19053
Closed
Open
Issue created Dec 12, 2020 by Arthur Khashaev@inviz

Strange behavior when using -O

Summary

I've encountered a strange behavior using ghc -O on the program with Prelude.last, Data.List.group, System.Exit, and IO effects.

Steps to reproduce

import Data.List (group)
import System.Exit (exitFailure, exitSuccess)

main :: IO ()
main = do
  _ <- getContents
  if last (group "a") == "a" then exitSuccess else exitFailure
ghc -O snippet.hs -o snippet && ./snippet

Actual behaviour

snippet: Prelude.last: empty list

Even strange, this can be fixed in one of the following ways:

  • Compiling without -O.
  • Removing _ <- getContents.
  • Reducing (group "a") to ["a"] or last (group "a") to "a".

Expected behavior

I expect successful exit without Prelude.last: empty list error.

Environment

  • GHC version used: The Glorious Glasgow Haskell Compilation System, version 8.6.5 from deb package ghc/focal 8.8.1+dfsg1+is+8.6.5+dfsg1-3 amd64.

Optional:

  • Operating System: Linux host 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • System Architecture: x86_64
Edited Dec 12, 2020 by Arthur Khashaev
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking