Source shown in error messages can be wrong if file changes during compilation
Summary
Sometimes the source shown in an error message can be wrong (too new) if the file is changed during compilation.
Example:
src/PlutusTx/AssocMap.hs:242:55: error:
• Expecting two more arguments to ‘Map’
Expected a type, but ‘Map’ has kind ‘* -> * -> *’
• In the fourth argument of ‘PlutusTx.LiftU’, namely ‘Map’
In the stand-alone deriving instance for
‘PlutusTx.LiftU name uni fun Map’
|
242 | deriving newtype instance PlutusTx.LiftU name uni fun (Map k v)
| ^^^
I added the k
and v
parameters while the compilation was happening.
You can see that the source is wrong (it contains k
and v
), and caret (and the highlight) is in the wrong place (corresponding to the old source, I guess). I think the error is using the source location from the file at the start of compilation, but reading the file back when the error is reported to make the final message.
This is a bit of an edge case so it's probably not worth that much effort to fix!
Steps to reproduce
- Start compiling a file with an error in.
- Edit the line with the error in before compilation finishes.
- Observe that the wrong source appears.
Expected behavior
I think the most reasonable behaviour is to show the source as it was when compilation began. This may require reading it in at that point and saving it until error reporting is done.
Environment
- GHC version used: 8.10.7