Comments (13)
It looks like flycheck-haskell do not take cabal defined macros into account.
It doesn't. You can easily add the necessary macros to the corresponding options, though.
PS. Why dont just use cabal build to build modules, or just get all parameters which cabal gives to ghc using e.g. http://hackage.haskell.org/package/cabal-cargs ?
If you ask me this way, I'd say that I didn't yet need this myself, and none else–including you—has bothered to make a pull request… not that I'd merge it, though, because I do have reasons for the things I do, you know.
from flycheck-haskell.
@lunaryorn: could you explain how to "add the necessary macros to the corresponding options"? I'm getting a similar error from #if !MIN_VERSION_base(4,8,0)
guards.
from flycheck-haskell.
@ntc2 There's flycheck-ghc-args
which is simple a list of additional flags for GHC in Flycheck. You can add -cpp
and -DMIN_VERSION_base(4, 8, 0)
to it to define the macro for Flycheck syntax checking/
from flycheck-haskell.
@lunaryorn: thanks for your help! Adding -cpp
and -DMIN_VERSION_base(4, 8, 0)
to flycheck-ghc-args
did not work for me, but I was able to find other settings that do work.
Following a blog (http://www.christopherbiscardi.com/tag/min_version_base/) I found that adding
"-I<absolute path in Cabal sandbox to>/build/autogen" "-optP-include" "-optPcabal_macros.h"
to flycheck-ghc-args
works, because cabal_macros.h
is where the MIN_VERSION
macros are defined.
Then, following @s9gf4ult 's suggestion, I found that installing cabal-cargs
and doing (setq flycheck-ghc-args (split-string (shell-command-to-string "cabal-cargs")))
achieves this in a more general way (although might be broken if any paths had spaces in them; my paths do not).
The above fixes make the FlyCheck haskell-ghc
checker succeed, but haskell-hlint
still fails with
Suspicious state from syntax checker haskell-hlint: Checker haskell-hlint returned non-zero exit code 1, but no errors from output: hlint: Cannot expand #if directive in file /home/conathan/cfar/reopt.git/src/Reopt/Concrete/flycheck_Semantics.hs at line 39 col 1:
MIN_VERSION_base(a,b,c) is not a defined macro
Checker definition probably flawed.
(No idea what's going on with the flycheck_
on the path in the error message.)
from flycheck-haskell.
@ntc2 The prefix comes from the temporary file that Flycheck creates to check modified buffers.
You'd need to define the macro for hlint as well, but I don't know how to do that. Presumably there's an hlint option for that, but it don't think it's wrapped in Flycheck.
Please open a new issue on Flycheck's main issue tracker for the hlint problem. Thanks.
from flycheck-haskell.
If anyone is having trouble with this, easiest solution, IMHO is this:
(setq
flycheck-ghc-args
'("-cpp"
"-DMIN_VERSION_base(a,b,c)"))
;; alternatively:
(require 'flycheck)
(add-to-list 'flycheck-ghc-args "-cpp")
(add-to-list 'flycheck-ghc-args "-DMIN_VERSION_base(a,b,c)")
This worked for me, no need to install anything with Cabal. Not sure there are any adverse effects.
Edit: there are still problems with hlint, this solution should work better once flycheck/flycheck#713 is fixed.
from flycheck-haskell.
@mrkkrp: in general any package <pkg>
can have a MIN_VERSION_<pkg>
macro -- I think Cabal generates one for each dependency in the .cabal
-- but in practice not many of them get used. So, no adverse effects, but that is not a general solution.
from flycheck-haskell.
@ntc2, Yeah, true, although I'm sure in 90% of cases it's base
. What about progress with that hlint issue? Should I try to add option for hlint parameters? Unless someone already doing this, I think I will open a PR, because this would fix the problem for me completely.
from flycheck-haskell.
@mrkkrp: it doesn't look like anything is happening on the hlint
issue. You're right that MIN_VERSION_base
is the common case, although grepping through projects I've worked on recently I also see MIN_VERSION_
macros for template_haskell
, time
, and directory
in use. Of course, it's not hard to add three more -D
args to flycheck-ghc-args
:)
from flycheck-haskell.
I clearly said right away that I won't add that myself and will leave that to someone else's pull request. I haven't got any so far after two months, so I'm definitely not going to take any blame for that issue still being open.
from flycheck-haskell.
@lunaryorn, I personally don't blame you at all, I just asked if anyone is already doing that.
from flycheck-haskell.
@lunaryorn: sorry, I was not intending to blame you or anyone else. I was just responding to @mrkkrp's question about whether any progress has been made on the issue. I really appreciate all your hard work on flycheck
; I have contributed nothing.
from flycheck-haskell.
@ntc2, OK, my PR introducing flycheck-hlint-args
has been merged, so now I use this:
(defun mk-haskell-set-min-versions (lib-list)
"Help Flycheck handle Cabal MIN_VERSION_ definitions.
LIB-LIST should of the following form:
(LIB-NAME V0 V1 V2)
Where LIB-NAME is a string, name of library and V0, V1, V2 are
version components."
(add-to-list 'flycheck-ghc-args "-cpp")
(add-to-list 'flycheck-hlint-args "-XCPP")
(dolist (item lib-list)
(cl-destructuring-bind (lib a b c) item
(add-to-list
'flycheck-ghc-args
(format "-DMIN_VERSION_%s(a,b,c)=(a<=%d&&b<=%d&&c<=%d)"
lib a b c))
(add-to-list
'flycheck-hlint-args
(format "--cpp-define=MIN_VERSION_%s(a,b,c)=(a<=%d&&b<=%d&&c<=%d)"
lib a b c)))))
(mk-haskell-set-min-versions
'(("base" 4 8 0)))
No, I don't like it either, but everything is working fine at last.
from flycheck-haskell.
Related Issues (20)
- flycheck-disable-checked not disabling haskell-stack-ghci HOT 6
- `flycheck-haskell-setup` signals error on Windows HOT 4
- Support for Haskell scripts made with Stack HOT 1
- Using flycheck in a docker-based stack project? HOT 1
- Bug in get-cabal-configuration.hs HOT 2
- call to stack / get-cabal-configuration delays editing file HOT 2
- IO mzero error when reading cabal configuration HOT 2
- cabal new-style builds HOT 1
- running hlint when installed using --copy-compiler-bins HOT 2
- Module ‘Distribution.PackageDescription.Parsec’ does not export ‘readGenericPackageDescription’
- Very bad performance HOT 4
- no errors HOT 7
- Paths_* modules cannot be found HOT 11
- Support hpack files directly HOT 3
- Flycheck with nix: Could not find module HOT 4
- Flycheck-haskell hangs indefinitely on NixOS HOT 6
- weird output from haskell-hlint checker HOT 2
- Support for cabal.project? HOT 1
- flycheck-haskell is very slow when stack.yaml is not pressent HOT 10
- Reference to Distribution.Parsec.Common needs to be updated for Cabal-3.0.0.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flycheck-haskell.