nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.59k stars 1.47k forks source link

Better compiler warning/error messages #7749

Closed jrenner closed 6 years ago

jrenner commented 6 years ago

Not to be cliche by comparing to Rust, but in learning some Rust recently I was blown away by how helpful the compiler error messages were. I think Nim could improve a lot in this area, and I might be interested in helping out if the maintainers think it would be a good idea.

Here is one example I ran across recently:

import strformat

let x = "{t}"
let fmt_x = x.fmt

compiler message: Error: & only works with string literals

improvement: might also mention something about "fmt", & made me think of string concat at first suggested new message: Error: strformat module string formatting (fmt(), &) only works with string literals

I'm curious what others think.

data-man commented 6 years ago

https://github.com/nim-lang/Nim/issues?q=is%3Aopen+is%3Aissue+label%3A"Error+messages"

jrenner commented 6 years ago

That search query doesn't seem to have any results for me.

I did however find this:

3914

It looks this is an area that could use some work.

kaushalmodi commented 6 years ago

@jrenner So how did you get around that limitation.. I have really long message formatting, and instead of copy/pasting the message, I wished I could store the string representing that format to a var and do fmt(VAR).

Here's a simple case:

import strformat
let
  a = 100
  msg = "a = {a}"

echo fmt(msg)

But here's that actual msg: "The '{argval}' value for ':{arg}' is invalid. The only valid values are 'yes' and 'no'.".