8000 Verbatim imports put at bottom of stanza first time · Issue #522 · sol/hpack · GitHub
[go: up one dir, main page]

Skip to content
8000

Verbatim imports put at bottom of stanza first time #522

Open

Description

@brandon-leapyear

#490 moves import lines to the top of the stanza, but it only happens the first time hpack is called.

Repro:

  1. Run rm *.cabal
  2. Add verbatim: { import: ... } line to a stanza
  3. Run hpack
  4. Cabal file incorrectly has import line at bottom
  5. Run hpack again
  6. Cabal file correctly has import line moved to top

Activity

  1. sol commented on Sep 21, 2022

    @sol
    Owner

    Hi @brandon-leapyear 👋 thanks for reporting this!

    This is something we want to fix. I am away from my computer for the next couple of days. Still, I took a quick look at the code. From what I understand, these are the underlying issues:

    1. I did not add a test with Always render imports as the first field of a section (fixes #486) #490. Our acceptance tests accept any field order, so adding an acceptance test may require some extra work. We have existing tests for field sorting in:
      it "keeps existing field order" $ do
      However the code added in #490 is not covered by those tests.
    2. We only sort stanza fields if we already have an existing fieldOrder (and by extension only when we already have a .cabal-file):
      Stanza name fields : xs | Just fieldOrder <- lookup name sectionsFieldOrder -> Stanza name (sortFieldsBy fieldOrder fields) : go xs
  2. brandon-leapyear commented on Sep 21, 2022

    @brandon-leapyear
    Author

    ✨ This is an old work account. Please reference @brandonchinn178 for all future communication ✨


    Makes sense! I don't know if you have any end-to-end tests, but I think a simple end-to-end test for this could be:

    1. In an empty directory, create package.yaml that imports a common stanza adding a dependency (e.g. aeson or containers) + write a library file using that dependency (such that a cabal file lacking that dependency would fail to build)
    2. In that directory, run hpack and cabal
    3. Build should succeed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Footer

      © 2026 GitHub, Inc.
      0