Skip to content

Commit

Permalink
fix: type variables by default should have Any kind (#6203)
Browse files Browse the repository at this point in the history
# Description

## Problem

Resolves #6202

## Summary

Or maybe this isn't the fix. 

On top of `Kind::Normal` it says:

```
    /// Can bind to any type, except Type::Constant and Type::InfixExpr
    Normal,
```

Does that exclude numeric generics? If not, then maybe the fix is
somewhere else 🤔

## Additional Context



## Documentation

Check one:
- [x] No documentation needed.
- [ ] 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.
  • Loading branch information
asterite authored Oct 2, 2024
1 parent b4712c5 commit 268f2a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ impl Type {
}

pub fn type_variable(id: TypeVariableId) -> Type {
let var = TypeVariable::unbound(id, Kind::Normal);
let var = TypeVariable::unbound(id, Kind::Any);
Type::TypeVariable(var)
}

Expand Down
18 changes: 18 additions & 0 deletions compiler/noirc_frontend/src/tests/turbofish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,21 @@ fn turbofish_in_struct_pattern_generic_count_mismatch() {
assert_eq!(*expected, 1);
assert_eq!(*found, 2);
}

#[test]
fn numeric_turbofish() {
let src = r#"
struct Reader<let N: u32> {
}
impl<let N: u32> Reader<N> {
fn read<let C: u32>(_self: Self) {}
}
fn main() {
let reader: Reader<1234> = Reader {};
let _ = reader.read::<1234>();
}
"#;
assert_no_errors(src);
}

0 comments on commit 268f2a0

Please sign in to comment.