Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import if/ELSE #8218

Open
eviefp opened this issue Jun 15, 2022 · 3 comments
Open

Import if/ELSE #8218

eviefp opened this issue Jun 15, 2022 · 3 comments

Comments

@eviefp
Copy link

eviefp commented Jun 15, 2022

Describe the bug
I would like to be able to use else clauses in import-if statements.

Related issue: #5563
Related PR: #5566

To Reproduce
A reasonably short repro is

cabal-version:      2.4
name:               cabal-import-if
version:            0.1.0.0

flag some-flag
  description:
  default: False
  manual: True

common common-1
  build-depends: aeson

common common-2
  build-depends: aeson-lens

executable cabal-import-if
    if flag(some-flag)
      import: common-1
    else
      import: common-1, common-2

    main-is:          Main.hs
    build-depends:    base ^>=4.14.3.0
    hs-source-dirs:   app
    default-language: Haskell2010

Expected behavior
Just having the if works, but adding the else results in a warning and ignoring the imports altogether.

System information

  • cabal 3.6.2.0

Additional context
For context, I am trying to work around the no multiple home units limitation. I am doing this because I want to be able to quickly run unit tests while editing both my lib and test units, i.e.:

  • reload/recompile fast when I make changes to lib
  • reload/recompile fast when I make changes to test
  • run unit tests by reloading the test Main file and running it

I was able to accomplish this by:

  • adding src to the test stanza's hs-source-dirs
  • copy over all build-depends from lib to test (they were transitive dependencies anyway)

The above allows me to run something like

$ ghcid -a -c "cabal repl my-test-stanza -f -O0" --test Main.main

and accomplish all I needed (i.e., fast reloads, run tests).

The problem now becomes, I would like to clean this up:

  • I dislike repeating the build-depends
  • I would rather have a flag that does the above and the addition to the tests' hs-source-dirs

So the way I tried was:

  • create a common stanza with the lib's build-depends
  • create a new flag
  • use that flag in test

The only problem is, the test stanza already has some common imports, so I can't merge them. I also can't move the if/else to the stanza, because I specifically need it to be always imported in lib but only when flag is set to `test.

@Mikolaj
Copy link
Member

Mikolaj commented Jun 15, 2022

OOI, if you add curly braces, does it work? if foo {...} else {...}

@eviefp
Copy link
Author

eviefp commented Jun 15, 2022

Still get an error on the else branch (so when running with -f-some-flag).

@Mikolaj
Copy link
Member

Mikolaj commented Jun 15, 2022

Thanks. Seems like an obvious improvement we'd like to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants