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

Use line pragmas for better error locations #9

Open
Toxaris opened this issue Jun 26, 2012 · 0 comments
Open

Use line pragmas for better error locations #9

Toxaris opened this issue Jun 26, 2012 · 0 comments

Comments

@Toxaris
Copy link
Contributor

Toxaris commented Jun 26, 2012

The Haskell pretty printer should generate {-# LINE ... #-} pragmas so that GHC error messages can point to locations in the source files (instead of locations in the generated files).

Example:

I have a file src/Foo/Bar/Test.shs:

module Foo.Bar.Test where

// main :: IO ()
main = "foo" + 13

SugarJ generates the following in bin/Foo/Bar/Test.hs:

module Foo.Bar.Test where
main = ( "foo" + 13 )  where {  }

This program does not typecheck, because the use of + in line 3 of Test.shs is not correct. GHC reports the problem, but points to line 2 of Test.hs:

    C:\eclipse\sugarj\workspace\test-project\bin\Foo\Bar\Test.hs:2:16:
        No instance for (Num [Char])
          arising from a use of `+'
        Possible fix: add an instance declaration for (Num [Char])
        In the expression: ("foo" + 13)
        In an equation for `main': main = ("foo" + 13)

It would be better if SugarJ could generate the following bin/Foo/Bar/Test.hs instead:

{-# LINE 1 "C:/eclipse/sugarj/workspace/test-project/src/Foo/Bar/Test.shs" #-}
module Foo.Bar.Test where
{-# LINE 3 "C:/eclipse/sugarj/workspace/test-project/src/Foo/Bar/Test.shs" #-}
main = ( "foo" + 13 )  where {  }

GHC would use the information in the LINE-pragmas to generate the following error message, which points to the correct line in the correct file:

C:\eclipse\sugarj\workspace\test-project\src\Foo\Bar\Test.shs:3:16:
    No instance for (Num [Char])
      arising from a use of `+'
    Possible fix: add an instance declaration for (Num [Char])
    In the expression: ("foo" + 13)
    In an equation for `main': main = ("foo" + 13)

Even better would be if SugarJ would parse this error messages and display it as an error marker on the line.

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

No branches or pull requests

1 participant