You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the most part type inference works fantastically in Noir, but there are some scenarios in which the type must be indicated explicitly. An example I keep running into is reading from public storage:
structMyStruct{x:Field,}implDeserializeforMyStruct{... }fnread<T,N>(storage_slot:Field) -> TwhereT:Deserialize<N>{T::deserialize(storage_read(storage_slot))}let foo = read(5);bar(foo.x);// The type of foo is uknown and `x` cannot be accessed
Interestingly I think I run into #4653 while trying out alternatives, but failed to realize it was an issue distinct from #4502.
The above can be fixed by annotating foo: MyStruct. This is (I think?) similar to Rust's collect() function, which may return multiple types (vectors etc). Unlike Rust however, we can't annotate just the missing part (i.e. the Vec), we must instead annotate the full type.
In the example above, if MyStruct was generic over a number of types, those would need to be also explicitly laid out, which I found ends up quickly polluting the sorrounding code and requiring extra type annotations in additional places.
Happy Case
It'd be great if we could have partial type inference, so that I only need to list the types that are actually ambiguous. Rust uses _ to indicate types that remain implicit, e.g. let foo: Vec<_> = bar.collect().
Project Impact
Nice-to-have
The text was updated successfully, but these errors were encountered:
Problem
For the most part type inference works fantastically in Noir, but there are some scenarios in which the type must be indicated explicitly. An example I keep running into is reading from public storage:
Interestingly I think I run into #4653 while trying out alternatives, but failed to realize it was an issue distinct from #4502.
The above can be fixed by annotating
foo: MyStruct
. This is (I think?) similar to Rust'scollect()
function, which may return multiple types (vectors etc). Unlike Rust however, we can't annotate just the missing part (i.e. theVec
), we must instead annotate the full type.In the example above, if
MyStruct
was generic over a number of types, those would need to be also explicitly laid out, which I found ends up quickly polluting the sorrounding code and requiring extra type annotations in additional places.Happy Case
It'd be great if we could have partial type inference, so that I only need to list the types that are actually ambiguous. Rust uses
_
to indicate types that remain implicit, e.g.let foo: Vec<_> = bar.collect()
.Project Impact
Nice-to-have
The text was updated successfully, but these errors were encountered: