[ruby-core:116830] [Ruby master Bug#20278] syntax error, unexpected local variable or method, expecting ')' (SyntaxError) - but I think it should report that a ',' is missing, or alternatively, that suggesting ')' is the most likely cause but not always (e. g. reword it a bit)

Issue #20278 has been reported by rubyFeedback (robert heiler). ---------------------------------------- Bug #20278: syntax error, unexpected local variable or method, expecting ')' (SyntaxError) - but I think it should report that a ',' is missing, or alternatively, that suggesting ')' is the most likely cause but not always (e. g. reword it a bit) https://bugs.ruby-lang.org/issues/20278 * Author: rubyFeedback (robert heiler) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- So this is not quite a bug, but I thought it may fit better here, as it is neither a feature, and also not quite fitting under misc. Before I will explain the issue, let me copy/paste the code I use so that others can reproduce what I mean: class Foobar def foo1 var1 = 1 var2 = 2 Foobar.some_method( var1 var2 ) end def self.some_method(a, b) puts a end end Foobar.new If it helps, the faulty lines are those between line 7 and 8, where I passed two variables var1 and var2, but I forgot a ',' between these two. I actually had this happen just now in another (real) code, and the error message confused me. Anyway, there are two things I want to report here. First, the smaller issue - the description show on the commandline is strange: expected a `)` to close the argumentsexpected a newline or semicolon after the statementcannot parse the expression Normally it should read "to close the arguments expected". It seems the ' ' space character between "arguments expected" is swallowed; same with the "statementcannot". But that is just description - I report it in the event someone else also finds it strange. I actually did not see it at first as I always look at the bottom first, so I tend to miss what appears on top. Anyway. The second one, and reason why I wrote this issue here, is that the error shown is a bit confusing: ack.rb:8: syntax error, unexpected local variable or method, expecting ')' (SyntaxError) var2 So ruby indicates that there is an issue with var2 and a ')' was expecting. But I think ruby should instead have expected a ','. I don't know whether ruby can distinguish between this; both var1 and var2 were already defined prior, so I think in theory the ruby parser could find out that there are two separate variables, and assume that a ',' could also be missing. I don't know if this is always the case, but at the least I think in the example code I showed, ruby saying that a ')' was expected, was wrong, in my opinion. Again, perhaps ruby has no way to distinguish, but as ruby gives a specific suggestion that there is a missing ')', when in reality I was missing the ',', is in my opinion incorrect. Perhaps it is not worth to fix it, but being able to distinguish at the least between two local variables (as in var1 and var2) should be possible, and perhaps the overall message shown could be improved a bit. For instance, the line " the argumentsexpected" could perhaps not only NOT swallow the ' ' but also be displayed on two lines. I am not sure if this makes it better or worse, since people's preferences are different. Either way I wanted to bring this to attention here. -- https://bugs.ruby-lang.org/

Issue #20278 has been updated by rubyFeedback (robert heiler). I just noticed that it actually already reported that a semicolon is missing: "expected a newline or semicolon" So I would like to reword the above to perhaps consider also showing this information in the raised message below: ack.rb:8: syntax error, unexpected local variable or method, expecting ')' (SyntaxError) Could then be: ack.rb:8: syntax error, unexpected local variable or method, expecting ')' or ',' (SyntaxError) ---------------------------------------- Bug #20278: syntax error, unexpected local variable or method, expecting ')' (SyntaxError) - but I think it should report that a ',' is missing, or alternatively, that suggesting ')' is the most likely cause but not always (e. g. reword it a bit) https://bugs.ruby-lang.org/issues/20278#change-106856 * Author: rubyFeedback (robert heiler) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- So this is not quite a bug, but I thought it may fit better here, as it is neither a feature, and also not quite fitting under misc. Before I will explain the issue, let me copy/paste the code I use so that others can reproduce what I mean: class Foobar def foo1 var1 = 1 var2 = 2 Foobar.some_method( var1 var2 ) end def self.some_method(a, b) puts a end end Foobar.new If it helps, the faulty lines are those between line 7 and 8, where I passed two variables var1 and var2, but I forgot a ',' between these two. I actually had this happen just now in another (real) code, and the error message confused me. Anyway, there are two things I want to report here. First, the smaller issue - the description show on the commandline is strange: expected a `)` to close the argumentsexpected a newline or semicolon after the statementcannot parse the expression Normally it should read "to close the arguments expected". It seems the ' ' space character between "arguments expected" is swallowed; same with the "statementcannot". But that is just description - I report it in the event someone else also finds it strange. I actually did not see it at first as I always look at the bottom first, so I tend to miss what appears on top. Anyway. The second one, and reason why I wrote this issue here, is that the error shown is a bit confusing: ack.rb:8: syntax error, unexpected local variable or method, expecting ')' (SyntaxError) var2 So ruby indicates that there is an issue with var2 and a ')' was expecting. But I think ruby should instead have expected a ','. I don't know whether ruby can distinguish between this; both var1 and var2 were already defined prior, so I think in theory the ruby parser could find out that there are two separate variables, and assume that a ',' could also be missing. I don't know if this is always the case, but at the least I think in the example code I showed, ruby saying that a ')' was expected, was wrong, in my opinion. Again, perhaps ruby has no way to distinguish, but as ruby gives a specific suggestion that there is a missing ')', when in reality I was missing the ',', is in my opinion incorrect. Perhaps it is not worth to fix it, but being able to distinguish at the least between two local variables (as in var1 and var2) should be possible, and perhaps the overall message shown could be improved a bit. For instance, the line " the argumentsexpected" could perhaps not only NOT swallow the ' ' but also be displayed on two lines. I am not sure if this makes it better or worse, since people's preferences are different. Either way I wanted to bring this to attention here. -- https://bugs.ruby-lang.org/
participants (1)
-
rubyFeedback (robert heiler)