forked from munificent/craftinginterpreters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix munificent#40. Since assignment is an expression, every assignment instruction (SET_LOCAL, SET_GLOBAL, SET_UPVALUE, SET_PROPERTY) needs to leave the RHS on the stack. SET_UPVALUE was accidentally consuming it, which leaves the stack in the wrong state.
- Loading branch information
1 parent
e27fb8e
commit f449809
Showing
3 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
fun caller(g) { | ||
g(); | ||
// g should be a function, not nil. | ||
print g == nil; // expect: false | ||
} | ||
|
||
fun callCaller() { | ||
var capturedVar = "before"; | ||
var a = "a"; | ||
|
||
fun f() { | ||
// Commenting the next line out prevents the bug! | ||
capturedVar = "after"; | ||
|
||
// Returning anything also fixes it, even nil: | ||
//return nil; | ||
} | ||
|
||
caller(f); | ||
} | ||
|
||
callCaller(); |