Skip to content

Assertion failure but nobody notices because assertions are off by default #106

@nh2

Description

@nh2

I'm building ghc-events as part of static-haskell-nix's CI, where sometimes I build with -O0.

An assertion appears:

test-versions: Assertion failed
CallStack (from HasCallStack):
  assert, called at src/GHC/RTS/Events/Binary.hs:822:5 in ghc-events-0.19.0.1-863kLHKqkAq5pQOjpORL0w:GHC.RTS.Events.Binary

That's this one:

assert (fromIntegral payloadLen ==
(sum
[ 8 -- tickyCtrDefId
, 2 -- tickyCtrDefArity
, textByteLen tickyCtrDefKinds
, textByteLen tickyCtrDefName
, 8 -- tickyCtrInfoTbl
, maybe 0 textByteLen tickyCtrJsonDesc
]))

I tested also with stack test on a stack.yaml with this config:

resolver:
  url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/25.yaml
packages:
- .

As documented in assert, it's disabled on -O, which cabal enables by default.

So probably nobody noticed that.

I recommend setting either

  ghc-options:      -Wall -fno-ignore-asserts

if assertions should be used in code, or not using assert.

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