From 8f44cbea23f5b31b922a887a719a2e32c5358f75 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 25 Aug 2019 22:55:53 -0300 Subject: [PATCH] parser: ensure calls only happen to Variables --- src/parser.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/parser.zig b/src/parser.zig index 9c1ce16..40404dd 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -694,10 +694,20 @@ pub const Parser = struct { } fn parseCall(self: *@This()) !*Expr { + // we parse a primary expression instead of consuming a .Identifier + // since parseCall is connected to the rest of the parser. doing + // identifiers would break the rest of the rules that want primaries. + + // nothing stops us from ensuring expr is a Variable though ;) var expr = try self.parsePrimary(); while (true) { if (self.check(.LeftParen)) { + if (ast.ExprType(expr.*) != .Variable) { + self.doError("cannot call non-variable{}", ast.ExprType(expr.*)); + return Result.CompileError; + } + _ = try self.consumeSingle(.LeftParen); expr = try self.finishCall(expr); } else {