Browse Source

[FIX] Bug that caused a function call with no parameters to throw SyntaxError

Include a test case for the bug above
Lucas de Souza 6 years ago
parent
commit
6a979d5b46
2 changed files with 32 additions and 0 deletions
  1. 4 0
      js/ast/ivprogParser.js
  2. 28 0
      tests/test18.spec.js

+ 4 - 0
js/ast/ivprogParser.js

@@ -953,6 +953,10 @@ export class IVProgParser {
   parseActualParameters () {
     this.checkOpenParenthesis();
     this.pos++;
+    if(this.checkCloseParenthesis(true)) {
+      this.pos++;
+      return [];
+    }
     this.consumeNewLines();
     const list = this.parseExpressionList();
     this.consumeNewLines();

+ 28 - 0
tests/test18.spec.js

@@ -0,0 +1,28 @@
+import Lexers from './../grammar/';
+import * as Expressions from './../js/ast/expressions/';
+import * as Commands from './../js/ast/commands/';
+import {Types} from './../js/ast/types';
+import {
+    IVProgParser
+} from './../js/ast/ivprogParser';
+
+describe('Call to a function that receives no parameter', () => {
+    let input = `programa {
+
+      funcao inicio() {
+        inteiro a
+        fun()
+      }
+
+      funcao fun() {
+        retorne
+      }
+    }`;
+    const lexer = Lexers['pt_br'];
+
+    it(`should not throw an Error`, () => {
+        const as = new IVProgParser(input, lexer);
+        const fun = as.parseTree.bind(as);
+        expect(fun).not.toThrow();
+    });
+});