dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
908 stars 211 forks source link

dhall-docs: Prelude.head: empty list #2576

Open kukimik opened 3 months ago

kukimik commented 3 months ago

Running the dhall-docs executable from the 1.42.0 release on the following file:

let isZero = \(x : Natural) -> x === 0
let errorGeneratingDocs
    = \(n : Natural) -> \(p : isZero n) ->
        True
in errorGeneratingDocs

results in:

dhall-docs: Prelude.head: empty list

A binary I compiled myself reveals some more detail:

CallStack (from HasCallStack):
  error, called at libraries/base/GHC/List.hs:1646:3 in base:GHC.List
  errorEmptyList, called at libraries/base/GHC/List.hs:85:11 in base:GHC.List
  badHead, called at libraries/base/GHC/List.hs:81:28 in base:GHC.List
  head, called at src/Dhall/Docs/CodeRenderer.hs:378:127 in dhall-docs-1.0.11-inplace:Dhall.Docs.CodeRenderer

The relevant code is:

https://github.com/dhall-lang/dhall-haskell/blob/4d21a1897e2c9e1ada8784dd521f7f24fa7311b6/dhall-docs/src/Dhall/Docs/CodeRenderer.hs#L375-L379

What I found out is that the bug seems somehow related to whitespace (e.g. removing the indentation or even replacing tabs with spaces makes the error disappear).