BUGFIX: chained calls not being dottified

This commit is contained in:
2022-11-04 11:13:40 +01:00
parent cceefa6375
commit 5d240f85a6
4 changed files with 11 additions and 62 deletions

View File

@@ -1,56 +0,0 @@
fn _b(self) {
print "running _b";
print self;
return self;
}
fn _c(self) {
print "running _c";
print self;
return self;
}
fn _d(self) {
print "running _d";
print self;
return self;
}
fn _e(self) {
print "running _e";
print self;
return self;
}
fn _f(self) {
print "running _f";
print self;
return self;
}
fn b() {
print "running b";
}
fn c() {
print "running c";
}
fn d() {
print "running d";
}
fn e() {
print "running e";
}
fn f() {
print "running f";
}
var a = 42;
print a.b().c().d().e().f();

View File

@@ -0,0 +1,9 @@
fn _add(self, inc) {
return self + inc;
}
assert 1.add(2).add(3).add(4) == 10, "dottify bugfix failed";
print "All good";

View File

@@ -798,12 +798,6 @@ static Opcode dot(Parser* parser, ASTNode** nodeHandle) {
return OP_EOF;
}
//hijack the function call, and hack in an extra parameter
if (node->binary.opcode == OP_FN_CALL) {
node->binary.right->fnCall.argumentCount++;
node->binary.opcode = OP_DOT;
}
(*nodeHandle) = node;
return OP_DOT; //signal that the function name and arguments are in the wrong order
}
@@ -1090,6 +1084,7 @@ static void dottify(Parser* parser, ASTNode** nodeHandle) {
if ((*nodeHandle)->type == AST_NODEBINARY) {
if ((*nodeHandle)->binary.opcode == OP_FN_CALL) {
(*nodeHandle)->binary.opcode = OP_DOT;
(*nodeHandle)->binary.right->fnCall.argumentCount++;
}
dottify(parser, &(*nodeHandle)->binary.left);
dottify(parser, &(*nodeHandle)->binary.right);

View File

@@ -184,6 +184,7 @@ int main() {
"dot-and-matrix.toy",
"dot-assignments-bugfix.toy",
"dot-chaining.toy",
"dottify-bugfix.toy",
"functions.toy",
"imports-and-exports.toy",
"index-arrays.toy",