Skip to content

Type checking not order irrelevant although evaluation is #1725

Open
@cakemanny

Description

@cakemanny

Bug Report

It seems that I am able to write statements at the top-level in any order.
However, when I make a mistake which causes a type error, I get different errors depending on the order I wrote the statements. In fact, I only get it at type checking if the statements are written in order.

(Not sure where this is specified in the docs but it feels similar in idea to what is described about schemas: Irrelevant Order Calculation).

1. Minimal reproduce step

Create example.k, with the given contents and run kcl run example.k

f = lambda a: str, b: str -> str {
    a + "/" + b
}

items = {
    k: f(k, v) for k, v in _xs
}

_xs = {
    "https://aaa.example.com" = [
        "XX-01"
        "XX-02"
    ]
    "https://bbb.example.com" = [
        "XY-01"
        "XY-02"
    ]
}

2. What did you expect to see?

error[E2G22]: TypeError
  --> .../kcl-bugs/example.k:7:13
  |
7 |     k: f(k, v) for k, v in _xs
  |             ^ expected str, got [str]
  |

 --> .../kcl-bugs/example.k:2:20
  |
2 | f = lambda a: str, b: str -> str {
  |                    ^ variable is defined here, its type is str, but got [str]
  |

3. What did you see instead

EvaluationError
 --> .../kcl-bugs/example.k:7:1
  |
7 |     k: f(k, v) for k, v in _xs
  |  expect str, got list
  |

4. What is your KCL components version?

% kcl version
0.10.7-darwin-arm64

Why did you expect to see what you expected to see?

Glad you asked!

kcl run on the following code gives the expected type errors. It's the same but with items constructed below _xs instead of above.

f = lambda a: str, b: str -> str {
    a + "/" + b
}

_xs = {
    "https://aaa.example.com" = [
        "XX-01"
        "XX-02"
    ]
    "https://bbb.example.com" = [
        "XY-01"
        "XY-02"
    ]
}

items = {
    k: f(k, v) for k, v in _xs
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or requestresolvertype-systemIssues or PRs related to kcl type system

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions