**How to reproduce**
* Working query
```sql
WITH arrayJoin(range(2)) AS delta
SELECT
    toDate(time) + toIntervalDay(delta) AS dt,
    version()
FROM 
(
    SELECT NOW() AS time
)

┌─────────dt─┬─version()──┐
│ 2020-11-01 │ 20.10.3.30 │
│ 2020-11-02 │ 20.10.3.30 │
└────────────┴────────────┘

2 rows in set. Elapsed: 0.006 sec. 

```

* After adding ORDER BY dt
```sql
WITH arrayJoin(range(2)) AS delta
SELECT
    toDate(time) + toIntervalDay(delta) AS dt,
    version()
FROM 
(
    SELECT NOW() AS time
)
ORDER BY dt ASC


Received exception from server (version 20.10.3):
Code: 43. DB::Exception: Received from localhost:9000. DB::Exception: Illegal type Date of argument of function range. 

0 rows in set. Elapsed: 0.022 sec. 
```
* Try to change range(2) to equivalent array [0,1]
```sql
WITH arrayJoin([0, 1]) AS delta
SELECT
    toDate(time) + toIntervalDay(delta) AS dt,
    version()
FROM 
(
    SELECT NOW() AS time
)
ORDER BY dt ASC


Received exception from server (version 20.10.3):
Code: 43. DB::Exception: Received from localhost:9000. DB::Exception: Argument for function arrayJoin must be Array.. 

0 rows in set. Elapsed: 0.004 sec. 
```

**Expected behavior**
Correctly ordered result set

**Additional context**
Both queries with errors correctly run on version 20.7.2.30 
```sql
WITH arrayJoin(range(2)) AS delta
SELECT 
    toDate(time) + toIntervalDay(delta) AS dt,
    version()
FROM 
(
    SELECT NOW() AS time
)
ORDER BY dt ASC

┌─────────dt─┬─version()─┐
│ 2020-11-01 │ 20.7.2.30 │
│ 2020-11-02 │ 20.7.2.30 │
└────────────┴───────────┘

2 rows in set. Elapsed: 0.003 sec. 
```
```sql
WITH arrayJoin([0, 1]) AS delta
SELECT 
    toDate(time) + toIntervalDay(delta) AS dt,
    version()
FROM 
(
    SELECT NOW() AS time
)
ORDER BY dt ASC

┌─────────dt─┬─version()─┐
│ 2020-11-01 │ 20.7.2.30 │
│ 2020-11-02 │ 20.7.2.30 │
└────────────┴───────────┘

2 rows in set. Elapsed: 0.001 sec. 
```


{
        if (const auto * ast_function = ast->as<ASTFunction>())
            visit(*ast_function, data);
    }
    static void visit(const ASTFunction & ast_function, Data & data)
    {
        if (data.isRejected())
            return;
        
        auto arguments = ast_function.arguments;
        if (arguments->children.size() != 1)
        {
            data.reject();
            return;
        }
        if (!data.canOptimize(ast_function))
        {
            data.reject();
            return;
        }
        const auto & function = FunctionFactory::instance().tryGet(ast_function.name, data.context);
        if (!function)
        {
            data.reject();