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

Add type checking for numeric kinds #5447

Closed
vezenovm opened this issue Jul 8, 2024 · 0 comments · Fixed by #5837
Closed

Add type checking for numeric kinds #5447

vezenovm opened this issue Jul 8, 2024 · 0 comments · Fixed by #5837
Labels
bug Something isn't working

Comments

@vezenovm
Copy link
Contributor

vezenovm commented Jul 8, 2024

Aim

The following code should fail with a type mismatch error:

fn foo<let N: u32>() -> u64 {
    N as u64
}

global J: u64 = 10;

fn bar<let N: u64>() -> u64 {
    foo::<J>()
}

global M: u64 = 3;

fn main() {
    let _ = bar::<M>();
}

Expected Behavior

I expect the code above to fail that we expected a u32 for the numeric generic being passed to foo. The function foo's numeric generic N has a numeric kind with an inner type of u32. This should be type checked against the global J's type of u64 and result in an error.

Bug

The code snippet above passes without error.

To Reproduce

  1. Run nargo compile on the snippet above

Project Impact

Nice-to-have

Impact Context

This is not a blocker for using numeric generics but developers could inadvertently use incorrect types which can lead to other bugs or confusion. We should still look to resolve this as soon as possible.

Workaround

No, aside just the developer themselves just passing the correct types.

Workaround Description

Additional Context

This may become a bit easier as part of (#5156) where we are already expecting to generalize the kind check inside of resolve_type_inner.

No response

Installation Method

None

Nargo Version

No response

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@vezenovm vezenovm added the bug Something isn't working label Jul 8, 2024
michaeljklein added a commit that referenced this issue Sep 3, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 17, 2024
# Description

## Problem\*

- Resolves #5156
- Resolves #5447

## Summary\*



## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [x] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Maxim Vezenov <[email protected]>
Co-authored-by: jfecher <[email protected]>
Co-authored-by: Tom French <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant