public function resolve($sym, $type=Symbol::T_NULL) {
        $val = $sym;
        if($sym instanceof \ECL\Symbol) {
           $val = $this->offsetGet($sym->getName());
           if($type == Symbol::T_NULL) {
               $type = $sym->getType();
           }
        }

        switch($type) {
        case Symbol::T_INT:
            $val = (int) $val;
            break;
        case Symbol::T_FLOAT:
            $val = (double) $val;
            break;
        case Symbol::T_STR:
            $val = (string) $val;
            break;
        case Symbol::T_LIST:
            if(!is_array($val)) {
                if(!($val instanceof \ECL\ResultSet)) {
                    throw new WrongTypeException($sym->getName());
                }
                $val = array_unique(\ECL\Util::pluck($val->getAll(), $sym->getPath()));
            }
            break;
        case Symbol::T_RES:
            if(!is_array($val)) {
                if(!($val instanceof \ECL\ResultSet)) {
                    throw new WrongTypeException($sym->getName());
                }
            } else {
                $val = new \ECL\ResultSet(array_map(function($x) { return ['value' => $x]; }, $val), ['value']);
            }
            break;
        }

        return $val;
    }