Fix #592: Local variable saw_eol in Class_Statements() was always true (#646)

The saw_eol variable in Class_Statements() was initialized to true and
only ever set back to true, making the "missing line separator" check
unreachable. The fix separates Def (block statement ending with }) from
Var_Decl (simple statement) so that Var_Decl sets saw_eol to false,
matching the pattern used in Statements() for simple expressions.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
leftibot 2026-04-11 08:32:27 -06:00 committed by GitHub
parent e42497a8b3
commit 7b45fe19fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -2736,7 +2736,7 @@ namespace chaiscript {
while (has_more) { while (has_more) {
const auto start = m_position; const auto start = m_position;
if (Def(true, t_class_name) || Var_Decl(true, t_class_name)) { if (Def(true, t_class_name)) {
if (!saw_eol) { if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", throw exception::eval_error("Two function definitions missing line separator",
File_Position(start.line, start.col), File_Position(start.line, start.col),
@ -2745,6 +2745,15 @@ namespace chaiscript {
has_more = true; has_more = true;
retval = true; retval = true;
saw_eol = true; saw_eol = true;
} else if (Var_Decl(true, t_class_name)) {
if (!saw_eol) {
throw exception::eval_error("Two expressions missing line separator",
File_Position(start.line, start.col),
*m_filename);
}
has_more = true;
retval = true;
saw_eol = false;
} else if (Eol()) { } else if (Eol()) {
has_more = true; has_more = true;
retval = true; retval = true;

View File

@ -0,0 +1,23 @@
// Test that two var declarations on the same line in a class body
// are rejected with a "missing line separator" error (issue #592)
try {
eval("class Foo { var x var y }")
assert_true(false)
} catch (eval_error) {
}
// Also verify that properly separated declarations still work
class Bar {
var x
var y
def Bar() {
this.x = 1
this.y = 2
}
}
auto b = Bar()
assert_equal(1, b.x)
assert_equal(2, b.y)