visitCall()

in lib/semantic.js [2343:2378]


  visitCall(ast, env) {
    assert.ok(ast.type === 'call');
    if (ast.left.type === 'method_call') {
      this.visitMethodCall(ast, env);
      return;
    }

    // need fix the type by id type
    if (ast.left.type === 'static_or_instance_call') {
      const id = ast.left.id;
      this.checkId(id, env);
      if (env.local.hasDefined(id.lexeme) || isTmpVariable(id.type)) {
        ast.left.type = 'instance_call';
        this.visitInstanceCall(ast, env);
        return;
      }

      if (this.dependencies.has(id.lexeme) || builtin.has(id.lexeme)) {
        ast.left.type = 'static_call';
        this.visitStaticCall(ast, env);
        return;
      }

      if (id.tag === Tag.VID) {
        this.checkVid(id, env);
        const type = this.getVariableType(ast.left.id, env);
        if (type.type === 'module_instance') {
          ast.left.type = 'instance_call';
          this.visitInstanceCall(ast, env);
          return;
        }
      }
    }

    throw new Error('un-implemented');
  }