Hi Markus,
On 20-5-2016 14:40, Markus Klinik wrote:
Hi,
In some cases, the line number in an error message does not point to the
place in the source code where the error actually comes from.
After parsing, for multi line expressions it usually shows the line
number of the beginning of the expression, or the =, -> or # before the
expression.
For example, when you compile the following program in the StdEnv
environment.
module compileErrorList
import StdEnv
test =
[ 10
, 20
, 30 + "foo"
]
Start = Start
You get this error message.
Type error [compileErrorList.icl,3,test]:"argument 1 of +" cannot unify
types:
String
Int
The error message points to line 3, while the error comes from line 6.
The rest of the error message identifies the argument of the plus
operator as the culprit. It seems that the compiler in principle has
enough information to pinpoint the origin of the error more precisely.
The syntax tree that is used by the type checker does not contain
detailed line number information. In this case it can only determine
the line number at the beginning of the function. The position of
the right hand side of the function is usually available, but in this
case it is lost before type checking.
If such a unify type error occurs, only the function name and argument
number is available, not the expression. I have updated the compiler, so
that the expression is also available, and committed the changes to
the svn repository. It now shows the following error message:
Type error [compileErrorList.icl,3,test]:"argument 1 of + : 30 " cannot
unify demanded type with offered type:
String
Int
Another example is the following program, which must be compiled in the
iTasks environment.
module compileErrorMonad
import Control.Monad
import System.IO
test =
putStrLn "hello">>|
putStrLn "world">>|
putStrLn 42
Start = Start
The error message is:
Type error [compileErrorMonad.icl,4,test]:"argument 1 of putStrLn" cannot
unify demanded type with offered type:
String
Int
The compiler seems to know that the argument of the third putStrLn is the
problem, but the source location of the error message points to line 4.
Because 42 is now included in the error message, the third putStrLn must
be the one with the problem:
Type error [compileErrorMonad.icl,4,test]:"argument 1 of putStrLn : 42"
cannot unify demanded type with offered type:
String
Int
Is it possible to let the compiler output source locations that relate
more closely to the origin of errors?
In this case it would be possible, if the syntax tree contained more
information about the positions of expressions.
Kind regards,
John van Groningen
Best regards,
Markus
_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list
_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list