Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type checking not order irrelevant although evaluation is #1725

Open
cakemanny opened this issue Oct 29, 2024 · 0 comments
Open

Type checking not order irrelevant although evaluation is #1725

cakemanny opened this issue Oct 29, 2024 · 0 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request resolver type-system Issues or PRs related to kcl type system

Comments

@cakemanny
Copy link

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
}
@Peefy Peefy added enhancement New feature or request type-system Issues or PRs related to kcl type system labels Oct 29, 2024
@Peefy Peefy added this to the v0.11.0 Release milestone Oct 29, 2024
@Peefy Peefy added bug Something isn't working resolver labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request resolver type-system Issues or PRs related to kcl type system
Projects
None yet
Development

No branches or pull requests

3 participants