Comments (8)
If I can give my two cents here: the Rust compiler does that and I really dislike this behaviour. This is just my experience but here's what happens to me most of the times: I'm quickly writing some code and put a todo somewhere just to make the code compile, and now I get two warnings:
pub fn main() {
let a = todo
// ^^^^ Todo used: your program will crash
wibble(1, a)
//^^^^^^^^^^^^ Unreachable
"some stuff"
}
What I just wanted was for the compiler to tell me where a todo is, not that what comes below is unreachable, I already know that since it tells me the program will crash here.
But now I get double the warnings and the second one is moving my focus away from the source of the problem (the todo) and is asking me to focus on the result of the problem (the following lines are unreachable because of the todo). That's not useful at all: the solution is still taking care of that todo as the first warning was already saying.
At this point my reaction is "well this is not that useful" and I start dismissing that second warning, which is not something I want people to do with warnings.
This is just my experience but I hope you get the idea of the problem here: I'd rather have a focused warning for this specific confusing case rather than a warning that is just redundant/distracting 80% of the times
What could this look like? Something like this:
warning: Todo used as a function
┌─ /src/main.gleam:2:3
│
2 │ todo(expr)
│ ^^^^^^ This won't appear in the error message
`todo` is not a function and will crash before it can do
anything with these arguments.
Hint: if you want to display an error message you should
write `todo as "your error message here"`
See: https://tour.gleam.run/advanced-features/todo/
So now we have a second warning just for this possible confusing case -"Where's my error message??"- that explains clearly how to solve your issue. A generic "This code is unused" could be just confusing and redundant most of the times
from gleam.
the next line could be a valid string expression and at least todo could be used to stop the code execution at that point? the compiler could warn that followup expressions in the same block are not reachable after todo/panic if that's not the case?
from gleam.
Thank you
from gleam.
What I just wanted was for the compiler to tell me where a todo is, not that what comes below is unreachable, I already know that since it tells me the program will crash here.
The problem here is that while you in this case do know, we have had folks in the past be confused and not realise that some code was unreachable. Having said that, it was due to code that does not return rather than todo
or panic
.
How about we have that specialised error you've shared there, and we have an unreachable warning for panic
specifically?
from gleam.
I think that would be great! I can work on this one
from gleam.
Thank you
from gleam.
I have a couple of question regarding warnings, how do we want to display them? For example:
-
Do we highlight just the line after panic or the whole unreachable group of statements?
pub fn main() { panic let n = 1 n + 1 }
warning: Unreachable code ┌─ /src/warning/wrn.gleam:4:3 │ 4 │ ╭ let n = 1 5 │ │ { n + 2 } * 3 │ ╰───────────────^ This code is unreachable since it comes after a `panic`.
- What if panic is inside a list/function call/tuple, what do we highlight here?
What if panic is the last item of the list, does that change anything in the way we want to report the error?
pub fn main() { [1, 2, panic, 3, 4] }
What if the list is not the last expression in a block?pub fn main() { [1, 2, panic] }
pub fn main() { let l = [1, 2, panic, 3, 4] [0, ..l] }
- Another case where I'm not sure what would be best is if there's multiple blocks with a panic each:
Do we highlight everything below the first panic? Or do we raise two warnings, one highlighting
pub fn main() { let a = { panic 1 + 1 } panic a + 1 }
1 + 1
and one highlightinga + 1
? What if the firstpanic
is the last expression of its block (that would still make everything unreachable below it)?
from gleam.
I think copying whatever Rust does would be good.
from gleam.
Related Issues (20)
- Unable to give completions to LSP for dot completions HOT 2
- Support specifying multiple license files and other text files for the Hex tarball HOT 5
- No module has been found with the name `gleam/os`. HOT 5
- Case guard statement using constant from other module generates invalid JS code HOT 1
- Unicode Codepoints Improperly Handled by BitArrays
- docs gen - include and automatically render mermaid markdown code blocks HOT 1
- fail to compile ezstd HOT 3
- Do not complain about match on literal empty tuple HOT 3
- Invalid Erlang code generated when comparing type containing a function in case guard HOT 1
- Formatter formats constant lists of tuples incorrectly
- Improper Erlang Codegen of Scientific Notation Floats without Trailing Zeros HOT 1
- Improper Erlang Codegen of Scientific Notation Floats without Trailing Zeros HOT 1
- gleam publish does not allow utf8 symbols in gleam.toml description (but mix hex.publish does) HOT 1
- `Some checks were not successful` in CI HOT 4
- asdf local gleam version - move compile gleam binary into a bin subdir HOT 3
- Do not exit analysis when an import is invalid
- Do not exit analysis when a type alias is invalid
- Do not exit analysis when a custom type is invalid
- Do not exit analysis when a constant is invalid HOT 3
- Do not exit analysis when a function is invalid
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gleam.