Skip to content

Re #483 Accept main lib in shorthand syntax for dependencies#645

Merged
mpilgrem merged 1 commit intomainfrom
re483
May 4, 2026
Merged

Re #483 Accept main lib in shorthand syntax for dependencies#645
mpilgrem merged 1 commit intomainfrom
re483

Conversation

@mpilgrem
Copy link
Copy Markdown
Collaborator

@mpilgrem mpilgrem commented May 4, 2026

See:

Currently, something like:

spec-version: 0.36.0
name: myPackage
dependencies:
- base

library:
  source-dirs: src

internal-libraries:
  sublib1:
    source-dirs: sub1
  sublib2:
    source-dirs: sub2

executables:
  myExe:
    source-dirs: app
    main: Main.hs
    dependencies:
    - myPackage:{myPackage, sublib1, sublib2}

renders in the Cabal file as (extract):

executable myExe
  main-is: Main.hs
  hs-source-dirs:
      app
  build-depends:
      base
    , myPackage:{sublib1,sublib2}   <<<< The reference to the main library component is missing
  default-language: Haskell2010

This pull request seeks to fix that. A new test is added.

Copy link
Copy Markdown
Owner

@sol sol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great fix, thanks for digging into this!

  1. Semantically this is a correct fix.
  2. In a way you could say the bug was that the existing code did not pattern match on DependencyName. With that view, a proper fix will do pattern matching (see my suggestion below). This way somebody who reads the code can immediately see that all cases are handled, and none of the constructors are silently ignored. One additional benefit of this approach is that it keeps the order intact.
  3. Technically we should probably also pattern match on Dependency in fromCabal. https://hackage-content.haskell.org/package/Cabal-syntax-3.16.1.0/docs/Distribution-Types-Dependency.html#v:Dependency

Comment thread src/Hpack/Syntax/Dependencies.hs Outdated
@sol
Copy link
Copy Markdown
Owner

sol commented May 4, 2026

@mpilgrem please go ahead and merge when you're done.

@mpilgrem mpilgrem merged commit cc8e828 into main May 4, 2026
9 checks passed
@mpilgrem mpilgrem deleted the re483 branch May 4, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants