When I forget a semicolon (in languages that like those), it gives the the error on the next line instead of the one that I forgot the semicolon on. It makes sense once you think about it but, man, it trips me up sometimes
IntelliJ has a setting like that, it’ll auto correct/lint/format files on save. Super useful, except sometimes when it’ll fuck up your entire file because it placed a bracket at the wrong place.
I’ve had it do that at some point when I forgot a semicolon in Javascript at exactly the wrong position. You see, Javascript can work without semicolons and it’ll automatically add them for you, except in a few cases where you need to be explicit.
For example:
const mishmash = 13 + 'world'
[13].length
This will place the semicolon after the .length, turning the code into const mishmash = 13 + 'world'[13].length.
In my case, it tried to be smart about inserting a semicolon in an unexpected case, and it turned nested .map() call into something completely unexpected while I hit ctrl+a on unfinished code. Took me a git reset to get something readable out of the that file again!
As for Rust: using some macros tends to make it suggest baffling syntax alterations sometimes. When you fuck up a macro in such a way that the macro no longer generates correct syntax, you can get the Rust compiler to suggest placing semicolons halfway through statements or even words.
See, it’s this trying to be overly friendly nonsense I hate about JS. If you need semicolons, demand them. Don’t make it seem like you don’t then make your code break because it hudes that you do. My first orogramming job was at large multinational japanese motor company and they had a hard rule over no in house exe’s or opensource software. So the compromise was doing everything in JS. JS refused to listen to me on doing a single threaded for loop, just run the loop, wait a moment, run the next one, wait a moment…
Doesn’t rust-analyser have the code suggestions that do fix it for you? It’s not fixing automatically, but it does know where it needs to go and it’s giving you a button that you click and it automatically fixes it
Oh yeah, it does. I’m not really complaining about fixing it myself. Mostly, I was joking that I felt like I’m unneeded. Rust-analyzer actually being able to fix it on its own, doesn’t help in that sense either. 🙃
I assumed we weren’t talking “expected semicolon” since that ones pretty explanatory and would never appear on a blank line. That said, it does provide an opportunity to talk about the worst code style I ever saw. A dude decided he wanted semicolons at the start of lines so that compiler error always mapped to the line he would have put the semicolon on
If you have optimizations enabled this can easily occur due to code being moved around behind the scenes. For example the body of a small function can be inserted where it is called. For example in c# if you get a null ref exception in such inlined code it will actually direct you to the place where the function is called from, rather than its body.
So if you know, you probably can find the issue. In the worst case just go to debug mode with opti off, or use an attribute on the function to force it not to inline.
Yes! Does anyone actually know why this happens!?
The error is usually with the line before
EDIT: could be a missing bracket:
or a comparison in place of an assignment:
Some thoughts based on personal experience:
It depends on what you’re using. I see it most often with TypeScript when the source maps are incorrect
When I forget a semicolon (in languages that like those), it gives the the error on the next line instead of the one that I forgot the semicolon on. It makes sense once you think about it but, man, it trips me up sometimes
Definitely also depends on the language. Here’s e.g. Rust, the goddamn overachiever, pointing arrows and everything:
Often feels like, if you know where it needs to go, why ask me?
IntelliJ has a setting like that, it’ll auto correct/lint/format files on save. Super useful, except sometimes when it’ll fuck up your entire file because it placed a bracket at the wrong place.
I’ve had it do that at some point when I forgot a semicolon in Javascript at exactly the wrong position. You see, Javascript can work without semicolons and it’ll automatically add them for you, except in a few cases where you need to be explicit.
For example:
const mishmash = 13 + 'world' [13].length
This will place the semicolon after the
.length
, turning the code intoconst mishmash = 13 + 'world'[13].length
.In my case, it tried to be smart about inserting a semicolon in an unexpected case, and it turned nested .map() call into something completely unexpected while I hit ctrl+a on unfinished code. Took me a git reset to get something readable out of the that file again!
As for Rust: using some macros tends to make it suggest baffling syntax alterations sometimes. When you fuck up a macro in such a way that the macro no longer generates correct syntax, you can get the Rust compiler to suggest placing semicolons halfway through statements or even words.
See, it’s this trying to be overly friendly nonsense I hate about JS. If you need semicolons, demand them. Don’t make it seem like you don’t then make your code break because it hudes that you do. My first orogramming job was at large multinational japanese motor company and they had a hard rule over no in house exe’s or opensource software. So the compromise was doing everything in JS. JS refused to listen to me on doing a single threaded for loop, just run the loop, wait a moment, run the next one, wait a moment…
JS, don’t help me, just do as I say
Doesn’t rust-analyser have the code suggestions that do fix it for you? It’s not fixing automatically, but it does know where it needs to go and it’s giving you a button that you click and it automatically fixes it
Oh yeah, it does. I’m not really complaining about fixing it myself. Mostly, I was joking that I felt like I’m unneeded. Rust-analyzer actually being able to fix it on its own, doesn’t help in that sense either. 🙃
Error: Unexpected the after the.
I assumed we weren’t talking “expected semicolon” since that ones pretty explanatory and would never appear on a blank line. That said, it does provide an opportunity to talk about the worst code style I ever saw. A dude decided he wanted semicolons at the start of lines so that compiler error always mapped to the line he would have put the semicolon on
At least there’s at least some benefit there :P
deleted by creator
If you have optimizations enabled this can easily occur due to code being moved around behind the scenes. For example the body of a small function can be inserted where it is called. For example in c# if you get a null ref exception in such inlined code it will actually direct you to the place where the function is called from, rather than its body.
So if you know, you probably can find the issue. In the worst case just go to debug mode with opti off, or use an attribute on the function to force it not to inline.