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

Tuples of tnteger types (i32, i128) are not ref convertible into Val #1327

Open
leighmcculloch opened this issue Jan 16, 2024 · 3 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@leighmcculloch
Copy link
Member

What version are you using?

20.0.0

What did you do?

let v: soroban_sdk::Val = (&0i128,).into_val(&env);

What did you expect to see?

Compiled, because all types are supposed to be value convertible 0i128.into_val(&env), ref convertible (&0i128).into_val(&env), and tuple convertible `(&0i128,).into_val(&env).

What did you see instead?

Compile error:

error[E0277]: the trait bound `soroban_sdk::Val: TryFromVal<Env, &i128>` is not satisfied
  --> src/test.rs:25:50
   |
25 |     let v: soroban_sdk::Val = (&0i128,).into_val(&env);
   |                                         -------- ^^^^ the trait `TryFromVal<Env, &i128>` is not implemented for `soroban_sdk::Val`
   |                                         |
   |                                         required by a bound introduced by this call
   |
   = help: the following other types implement trait `TryFromVal<E, V>`:
             <soroban_sdk::Val as TryFromVal<Env, State>>
             <soroban_sdk::Val as TryFromVal<Env, soroban_sdk::Vec<T>>>
             <soroban_sdk::Val as TryFromVal<Env, soroban_sdk::Address>>
             <soroban_sdk::Val as TryFromVal<Env, soroban_sdk::Symbol>>
             <soroban_sdk::Val as TryFromVal<Env, soroban_sdk::auth::Context>>
             <soroban_sdk::Val as TryFromVal<Env, ContractContext>>
             <soroban_sdk::Val as TryFromVal<Env, CreateContractHostFnContext>>
             <soroban_sdk::Val as TryFromVal<Env, soroban_sdk::auth::ContractExecutable>>
           and 110 others
   = note: required for `&i128` to implement `TryIntoVal<Env, soroban_sdk::Val>`
   = note: required for `soroban_sdk::Val` to implement `TryFromVal<Env, (&i128,)>`
   = note: required for `soroban_sdk::Val` to implement `FromVal<Env, (&i128,)>`
   = note: required for `(&i128,)` to implement `IntoVal<Env, soroban_sdk::Val>`
@leighmcculloch leighmcculloch added the bug Something isn't working label Jan 16, 2024
@anupsdf
Copy link
Contributor

anupsdf commented Jan 16, 2024

Looks like just SDK change to implement the trait and call env convert.rs

@jayz22
Copy link
Contributor

jayz22 commented Jan 16, 2024

The TryFromVal are all implemented for the types themselves (@anupsdf's finding above), not references.
So doing let v: Val = (0i128,).into_val(&env); without the & sign will work.
@leighmcculloch is there a reason why it needs to work with the references?

@leighmcculloch
Copy link
Member Author

@jayz22 I've tried to always provide both so that we can have a ref of something and still get a Val out of it.

If you have a ref of something and first need to get an owned value of it, that's tricky, because then you need it to impl ToOwned or Clone, and types may not implement those things.

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
None yet
Development

No branches or pull requests

4 participants
@leighmcculloch @jayz22 @anupsdf and others