I'm using the MultiWayIf language extension. While I love HLint (I'm using version v1.8.61), unfortunately it appears that HLint is not aware of this extension, and it reports multi-way ifs as parse errors:
Warning: Parse error: |
The HLint Manual (http://community.haskell.org/~ndm/darcs/hlint/hlint.htm) describes how you can use pragmas to indicate suggestions to ignore; however, this doesn't seem to work for warnings due to parse errors.
Is there any way to tell HLint to ignore the parse error warnings?
Thank you!
You can run:
hlint "--ignore=Parse error" MyFile.hs
There is a test that this invocation works in the HLint test suite.
Note that as soon as there is a parse error you won't get any other hints from the file, since HLint can't operate on a file until it is parsed.
However, if you upgrade to haskell-src-exts-1.15 or higher then reinstall HLint it should parse multi-way-if fine. If not, please report a bug.
Related
I'm puzzled by a failure of my doctests on GHC-7.10.3 and older. The full error message is
Data/ByteString/Builder/HTTP/Chunked.hs:75:0:
error: missing binary operator before token "("
#if MIN_VERSION_base(4,8,0)
^
doctests: doctests: phase `C pre-processor' failed (exitcode = 1)
With GHC >= 8.0 the tests work as intended. In all cases I'm using doctest-0.15.0.
EDIT: What I gather from https://ghc.haskell.org/trac/ghc/ticket/10970 is that the MIN_VERSION_ macros were originally defined by cabal, but have been generated by GHC itself since v8.0. It appears that cabal v2.2 still produces the macros for GHC < 8.0 so e.g. new-build works but doctest bypasses cabal.
Can someone suggest a good workaround?
For those hit by this: another reason for the error is that if you have say #if MIN_VERSION_template_haskell(1,2,3) in your code, but forgot to add template-haskell to package dependencies in the .cabal file then you also get this error.
The fix is to add it to the dependencies :)
When parsing source codes with c preprocessor enabled, the parser doesn't like undefined macros like MIN_VERSION_packagename(a,b,c). How can I get cabal/ghc tell cpp the package info and add the macro definitons?
You can use the very idiomatic (/s) options:
ghc -optP-include -optPdist/build/autogen/cabal_macros.h
I happen to have just been writing a pull request to doctest about this, you may be interested in referencing it:
https://github.com/sol/doctest/pull/109/files#diff-438bc19bd41887f8cacb796eaa990b0aR81
So, I'm trying to use the Plugins package to dynamically load a haskell function from a source file. The source file depends on a package foo with module Foo.Bar. I'm running my project in a Cabal sandbox, where I have foo installed. Both my main program, and the module I'm loading with plugins, depend on foo. I always get one of the following two errors:
When I have foo installed in ~/.cabal, I get the error:
GHCi runtime linker: fatal error: I found a duplicate definition for symbol
aizmvszmaizmlibzm0zi1_FooziBar_zdfTypeableBazzuds2_closure
whilst processing object file
/home/joey/.cabal/lib/foo-0.1/ghc-7.6.3/HSfoo-0.1.o
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation. Exiting now. Sorry.
When I don't have it installed in ~/.cabal, I get a standard "module not found" error. And when I don't have it installed in my sandbox, I get the same module not found error trying to compile my main program code.
The plugins documentation is scarce at best. Any thoughts on how to solve this?
I got this working by using System.Plugins.Make to actually do the compliation, instead of relying on pre-existing object files. Not a complete solution, doesn't explain the problem, but it works for me for now.
I have a module which binds to a C function using the FFI. How can I make this module use doctest?
The error I get when running doctest Foo.hs is something like this:
ByteCodeLink: can't find label
During interactive linking, GHCi couldn't find the following symbol:
bar
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session. Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
glasgow-haskell-bugs#haskell.org
### Failure in Foo.hs:41: expression `foo'
expected: [42]
but got:
<interactive>:24:1: Not in scope: `bar'
Examples: 2 Tried: 2 Errors: 0 Failures: 1
Doctest accepts arbitrary GHC flags. If you want to run Doctest with FFI code you need to pass the exact same flags that you would need to run a GHCi session with that code. Have e.g. a look at the Doctest driver of unix-time.
When I prototype Haskell programs, I always get hundreds of warnings like this (not joking):
/Users/bob/SourceCode/course/is/expriment/LiftedSpine2.hs:70:15:
Warning: Defined but not used: `ta'
/Users/bob/SourceCode/course/is/expriment/LiftedSpine2.hs:72:15:
Warning: Defined but not used: `ta'
/Users/bob/SourceCode/course/is/expriment/LiftedSpine2.hs:77:26:
Warning: Defined but not used: `v'
Is there anyway to remove these warnings temporarily?
I tried putting this in my .hs file:
{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-name-shadowing
-fwarn-monomorphism-restriction -fwarn-hi-shadowing
#-}
Unfortunately, it does not work, and although I also tried to :set -fno-warn-unused-binds, it still does not work.
Many thanks!
Another possibility, depending on your situation: I believe you can prefix identifiers with an underscore to suppress this warning. So:
_x = 42
will not generate the warning if _x is not used.
GHC has two warnings flags which can trigger Warning: Defined but not used.
You need some combination of the command line flags -fno-warn-unused-binds and -fno-warn-unused-matches.
I usually use -w to suppress all warnings when I want get rid of some warning temporarily.
I use a workaround for this:
I compile without warnings, but then I use HLint tool to display warnings for me. HLint has facilities to turn warnings separately.