parse error on output of ghc-mod #19

Closed
marcmo opened this Issue Sep 24, 2012 · 8 comments

Projects

None yet

3 participants

@marcmo
Contributor
marcmo commented Sep 24, 2012

trying to ghc-mod a haskell file that is using ffi.
ghc-mod output looks like this:

ghc-mod check a.hs
Dummy:0:0:Error:
ByteCodeLink: can't find label
During interactive linking, GHCi couldn't find the following symbol:
  voltageEvent
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

I would expect that ghcmod-vim will just note some kind of problem, but instead
I get a very long error hinting that there is a problem with the parse_make function:

Messages maintainer: Bram Moolenaar <Bram@vim.org>
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    8:
E688: More targets than List items
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E716: Key not present in Dictionary: filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E116: Invalid arguments for function s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line    9:
E15: Invalid expression: s:join_path(a:basedir, l:qf.filename)
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E684: list index out of range: 0
Error detected while processing function <SNR>124_receive..<SNR>105_on_finish..ghcmod#parse_make:
line   20:
E15: Invalid expression: l:texts[0]
@eagletmt
Owner

Could you show me your Haskell code that produces such an error message?

@marcmo
Contributor
marcmo commented Sep 27, 2012

you just need a haskell program that provokes the linking error, s.th. like

{-# LANGUAGE ForeignFunctionInterface #-}
module Main where

foreign import ccall "a.h foo" c_foo :: IO ()

main = c_foo

When I put this in a file a.hs and check it with ghc-mod I get:

ghc-mod check a.hs 
Dummy:0:0:Error:
ByteCodeLink: can't find label
During interactive linking, GHCi couldn't find the following symbol:
  foo
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
@johntyree
Contributor

@marcmo, There's some problem with generating the interface file apparently.

I made some test files:
a.h: void foo();
a.c: void foo() {return;}

Then compiled with gcc -c a.c. to produce a.o.

If I now try ghc-mod check test.hs it gives your error.
Next I let ghc build the interface file: ghc test.hs a.o to produce an executable test and most importantly, test.hi.

Now ghc-mod check test.hs magically works.

Remove test.hi and it goes back to giving the error.

tldr; Build the project first to generate the interface files. Then ghc-mod will succeed with FFI calls.

@marcmo
Contributor
marcmo commented Sep 27, 2012

@johntyree
thanks for the hint.
I can build the project successfully...but I would still prefer that ghcmod-vim does not barf when s.th. is not yet building correctly. After all...I use ghc-mode not only to clean up my code but also to detect errors early.

@johntyree
Contributor

@marcmo unfortunately, ghcmod can't work correctly if the project doesn't compile because that means by definition that some types are ambiguous or impossible. The latest ghc can defer type errors until runtime, my fingers are crossed that this means finally that ghcmod will be able to work in the way we all want it to and let us check the types of things which do make sense even if the file doesn't build. After all, if the file builds I'm practically done :) .

I don't know anything about the ghc api or how difficult that would be though.

@marcmo
Contributor
marcmo commented Sep 27, 2012

@johntyree thanks again for your explanation. I understand that this is currently not a situation that ghc-mod can deal with.
Not sure what other conditions result in an error as well but this kind of screws up the usage of my autocmd

        autocmd BufWritePost *.hs GhcModCheckAndLintAsync

since whenever I save the buffer, I get this tons of error messages from ghcmod-vim.
I don't mind getting one error message but not as many as I do at the moment.
Maybe it is possible to somehow catch the parse error that apparently happens in ghcmod-vim and spit out a nice and simple user notification? could be just the output of ghc-mod that was not parsable...
I would really hate it to disable this hook since I love this ghcmod-vim feature!

@johntyree
Contributor

@marcmo yeah it's unfortunate.

I have a similar setup using syntastic so you might want to try that. It's another great plugin for all languages. I have syntastic report errors on save and then use GhcModCheckAndLint when I think the file is done and just needs cleaning.

@marcmo
Contributor
marcmo commented Oct 1, 2012

@eagletmt the solution I implemented in my branch seems to work for all cases that I tested it with. made a pull-request so you can check.

@eagletmt eagletmt pushed a commit that closed this issue Dec 11, 2012
@marcmo marcmo make parsing more robust (fixes #19)
if the output of ghc-mod cannot be parsed try to display what we got
and indicate to the user that there was a parse problem
de4a9e7
@eagletmt eagletmt closed this in de4a9e7 Dec 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment