Stream: ideas

Topic: Shadowing error messages


view this post on Zulip Isaac Van Doren (Jan 01 2024 at 22:05):

The error message you get when you shadow a def is very clear and helpful, but there are many instances where it is one of the first errors that gets reported, and is followed by several other confusing type errors caused by the shadowing. I always end up looking at the last error message first because it is the one visible right there in the terminal. Because of this, there have been many times where I've shadowed a def and then spent some time being confused by messy type errors because I don't see the shadowing error. It is frustrating to run into because the solution is always so simple.

If shadowing errors either caused type checking to fail immediately, or if they were reported last, this would no longer be an issue. Thoughts?

view this post on Zulip Isaac Van Doren (Jan 02 2024 at 02:07):

I saw a message from Ayaz agreeing about moving the shadowing error message to last but it seems to have disappeared. I created an issue about this here https://github.com/roc-lang/roc/issues/6335

view this post on Zulip Eli Dowling (Jan 04 2024 at 02:04):

I was actually going to make a post about this exact issue today because it was driving me up the wall :sweat_smile:

view this post on Zulip Eli Dowling (Jan 04 2024 at 02:07):

I have accidentally shadowed a variable name of an import deep inside another block of code. It took me an embarrassingly long amount of time to figure out what the hell was going on

view this post on Zulip Eli Dowling (Jan 04 2024 at 02:07):

But I hit this issue probably five times in 2 hours of coding

view this post on Zulip Eli Dowling (Jan 04 2024 at 02:09):

I think it's also made much worse inside an IDE because I can't actually see the shadow error if it's off the screen whereas if you run the compiler at least it shows up in the list

view this post on Zulip Isaac Van Doren (Jan 04 2024 at 03:43):

Yes it is definitely frustrating. I started looking at it tonight and will open a PR to change the ordering soon!

view this post on Zulip Isaac Van Doren (Jan 04 2024 at 04:33):

PR here

view this post on Zulip Eli Dowling (Jan 04 2024 at 05:31):

Unfortunately I don't think that will help the editor issue.
For that we really need some way to detect that a shadowing has occurred and show the error at the location a variable had been shadowed and then all references that would be shadowing if shadowing was possible.

Currently the error shows at the definition of the original variable which is basically useless

currently it looks like:

a="hi" #shadowing error
b=
  a=10 #no error at all
  c=a+1 #type error saying a is a string

Should look like :

a="hi" #no error
b=
  a=10 #shadowing error
  c=a+1 #error saying you shouldn't use a shadowed variable

view this post on Zulip Eli Dowling (Jan 04 2024 at 05:36):

I made a separate issue about language server display location because it's kind of a different domain https://github.com/roc-lang/roc/issues/6345

view this post on Zulip Isaac Van Doren (Jan 04 2024 at 13:51):

Great! For sure


Last updated: Jun 16 2026 at 16:19 UTC