When instantiating a constant, if the value expression contains any function calls that are not implemented directly on a type, but through a trait instead, then the code will fail to compile. This is a big road block for translating Solidity code using Charcoal.
Working:
contract;
use sway_libs::signed_integers::common::*;
use sway_libs::signed_integers::i256::*;
const VALUE: I256 = I256::from_uint(12345);
Working:
contract;
use sway_libs::signed_integers::common::*;
use sway_libs::signed_integers::i256::*;
const VALUE: u256 = I256::from_uint(12345).underlying();
NOT Working:
contract;
use sway_libs::signed_integers::common::*;
use sway_libs::signed_integers::i256::*;
const VALUE: I256 = I256::from_uint(12345).wrapping_neg();
Steps
The non-working example above uses the I256 struct and WrappingNeg trait from the sway_libs::signed_integers library.
Create a Forc project.
Create a constant using a function that is implemented through a trait.
Compile the project.
Possible Solution(s)
I'm not sure if trait calls are viewed differently than regular function calls, but they probably shouldn't be.
Related Component
compiler
Problem
When instantiating a constant, if the value expression contains any function calls that are not implemented directly on a type, but through a trait instead, then the code will fail to compile. This is a big road block for translating Solidity code using Charcoal.
Working:
Working:
NOT Working:
Steps
The non-working example above uses the
I256
struct andWrappingNeg
trait from thesway_libs::signed_integers
library.Possible Solution(s)
I'm not sure if trait calls are viewed differently than regular function calls, but they probably shouldn't be.
Notes
No response
Installed components