🐛 fix segfault in `var x = (var a,b) = (1,2)`

This commit is contained in:
ValKmjolnir 2023-08-20 16:48:53 +08:00
parent 88b039a82e
commit 98b0086656
2 changed files with 15 additions and 4 deletions

View File

@ -118,7 +118,11 @@ bool parse::check_tuple() {
}
bool parse::check_func_end(expr* node) {
auto type=node->get_type();
// avoid error parse caused nullptr return value
if (!node) {
return true;
}
auto type = node->get_type();
if (type==expr_type::ast_func) {
return true;
} else if (type==expr_type::ast_def) {
@ -154,7 +158,11 @@ bool parse::check_special_call() {
}
bool parse::need_semi_check(expr* node) {
auto type=node->get_type();
// avoid error parse caused nullptr return value
if (!node) {
return true;
}
auto type = node->get_type();
if (type==expr_type::ast_for ||
type==expr_type::ast_forei ||
type==expr_type::ast_while ||
@ -627,7 +635,9 @@ expr* parse::scalar() {
return null();
}
// check call and avoid ambiguous syntax
if (is_call(toks[ptr].type) && !(lookahead(tok::lcurve) && toks[ptr+1].type==tok::var)) {
// i don't know why using `&& !(lookahead(tok::lcurve) && toks[ptr+1].type==tok::var)`
// here, maybe we'll find the reason XD
if (is_call(toks[ptr].type)) {
auto call_node = new call_expr(toks[ptr].loc);
call_node->set_first(node);
while(is_call(toks[ptr].type)) {

View File

@ -13,6 +13,7 @@ var content = [];
var log_cache = "";
println("Nasal: This is experimental REPL");
println("Tips : \";\" is automatically added at the end of the input line.");
help();
var count_bracket = func(line) {