feat: disallow field references outside class definitions with explicit error

Add a check in the `field()` function to detect when a field is referenced outside of a class context. When `compiler->fields` is NULL (indicating no enclosing class), emit a clear error message "Cannot reference a field outside of a class definition." and assign a dummy field index of 255 to allow continued parsing with minimal cascading errors.

Also includes minor cleanup: remove two stale TODO comments about EOF checking and better error messages in `nextToken()` and `consume()`, and add a new test file `test/field/outside_class.wren` that verifies the error is produced for top-level field assignment.
This commit is contained in:
Bob Nystrom
2013-11-29 18:53:56 +00:00
parent fe7e9041d1
commit 1b3b50374f
2 changed files with 24 additions and 12 deletions
+1
View File
@@ -0,0 +1 @@
_field = "wat" // expect error