2

Instead of throwing an error, why doesn't the compiler add a semicolon to solve it?

Comments
  • 6
    The compiler can't modify the source code. For all it knows, maybe that samicolon error is caused by something completely different. A missing quote in an unrelated string? Maybe incorrect paths in the compile files due to a build script error? Could be any amount of things that might report a missing semi despite that not being the problem. If the compiler just silently made your code compile it might cause more damage than good.

    Honestly the best practice is to trust that programmer knows best and just point out problems preventing running the software.
  • 4
    If it did, it would be one hell of a buggy feature
  • 2
    there is no way to be 100% sure if that's the actual bug.
  • 3
    So that you know you have failed in life.
  • 1
    what hazard said.
    although technically it could, but it wouldn't be right to do so.
    also, it can't be sure that the missing semicolon is the actual problem, the problem might be far before it in some other syntax mistake which didn't make the tokenizer outright halt, but it confused it in a way which hardfaulted X tokens later on expecting a semicolon in the wrongly parsed segment.
  • 1
    Because trying to fix bugs automatically is a pretty bad idea at the current state of AI tech.
  • 1
    That's what ecmascript does. When it encounters an invalid token it tries inserting a semicolon to see if that solves it
  • 1
    @12bitfloat oh my God! I thought you were joking

    https://developer.mozilla.org/en-US...
  • 1
    @12bitfloat @asgs
    He was not joking. The reason you should Always Use a Linter with JS.
  • 1
    because the compiler expects _you_ to know what the hell you're doing.
  • 1
    Javascript has already did that.
Add Comment