Skip to content

add type check during eval time - #11475

Merged
WindSoilder merged 6 commits into
nushell:mainfrom
WindSoilder:eval_time_type_check
Jan 12, 2024
Merged

WindSoilder merged 6 commits into
nushell:mainfrom
WindSoilder:eval_time_type_check

Conversation

@WindSoilder

@WindSoilder WindSoilder commented Jan 3, 2024 •

Copy link
Copy Markdown
Contributor

Description

Fixes: #11438

Take the following as example:

def spam [foo: string] {
    $'foo: ($foo | describe)'
}
def outer [--foo: string] {
    spam $foo
}

outer

When we call outer, type checker only check the all for outer, but doesn't check inside the body of outer. This pr is trying to introduce a type checking process through Type::is_subtype() during eval time.

NOTE

I'm not really sure if it's easy to make a check inside the body of outer. Adding an eval time type checker seems like an easier solution. As a result: outer will be caught by runtime, not parse time type checker

cc @kubouch

User-Facing Changes

After this pr the following call will failed:

> outer
Error: nu::shell::cant_convert

  × Can't convert to string.
   ╭─[entry #27:1:1]
 1 │ def outer [--foo: any] {
 2 │     spam $foo
   ·          ──┬─
   ·            ╰── can't convert nothing to string
 3 │ }
   ╰────

Tests + Formatting

Done

After Submitting

NaN

@WindSoilder
WindSoilder marked this pull request as draft January 3, 2024 09:30
@WindSoilder
WindSoilder marked this pull request as ready for review January 3, 2024 14:31
Comment thread crates/nu-protocol/src/ty.rs Resolved
@kubouch

kubouch commented Jan 7, 2024

Copy link
Copy Markdown
Contributor

Seems good, I just have one question, but otherwise we could merge it after the release.

@WindSoilder
WindSoilder merged commit 7248180 into nushell:main Jan 12, 2024
@kubouch kubouch added the notes:fixes Noted in "Bug fixes" section label Jan 17, 2024
WindSoilder added a commit that referenced this pull request Jan 26, 2024
# Description
Fixes: #11595

The original issue is caused by #11475, we also need to make empty list
matches `list type` or `table type`

cc @amtoine 

# User-Facing Changes
Nan

# Tests + Formatting
Done
@hustcer hustcer added this to the v0.90.0 milestone Feb 3, 2024
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
Fixes: nushell#11438 

Take the following as example:
```nushell
def spam [foo: string] {
    $'foo: ($foo | describe)'
}
def outer [--foo: string] {
    spam $foo
}

outer
```
When we call `outer`, type checker only check the all for `outer`, but
doesn't check inside the body of `outer`. This pr is trying to introduce
a type checking process through `Type::is_subtype()` during eval time.

## NOTE
I'm not really sure if it's easy to make a check inside the body of
`outer`. Adding an eval time type checker seems like an easier solution.
As a result: `outer` will be caught by runtime, not parse time type
checker

cc @kubouch 

# User-Facing Changes
After this pr the following call will failed:
```nushell
> outer
Error: nu::shell::cant_convert

  × Can't convert to string.
   ╭─[entry nushell#27:1:1]
 1 │ def outer [--foo: any] {
 2 │     spam $foo
   ·          ──┬─
   ·            ╰── can't convert nothing to string
 3 │ }
   ╰────
```

# Tests + Formatting
Done

# After Submitting
NaN
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
Fixes: nushell#11595

The original issue is caused by nushell#11475, we also need to make empty list
matches `list type` or `table type`

cc @amtoine 

# User-Facing Changes
Nan

# Tests + Formatting
Done
@WindSoilder
WindSoilder deleted the eval_time_type_check branch February 27, 2024 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

null can be passed to typed positional

3 participants