Closed Lukasz2891 closed 2 weeks ago
This looks like a failure of type checking as this is not a valid call.
data_points.push(DataPoint::from_bytes(bytes));
Changing that line to this produces the correct error:
let points = DataPoint::from_bytes(bytes);
data_points.push(points);
error
--> /home/igi-111/Code/test_sway/src/main.sw:32:13
|
30 | pub fn make_data_package(bytes: Bytes) -> (DataPackage, u64) {
31 | let mut data_points = Vec::new();
32 | let a = DataPoint::from_bytes(bytes);
| ^^^^^^^^^^^^^^^^^^^^^ Trait "FromBytesConvertible" is not implemented for type "DataPoint".
33 | data_points.push(a);
34 |
|
____
Evidently, call parameters expressions are not properly checked for type constraints here.
Here's a minimal example that reproduces the error:
script;
use std::{
bytes::Bytes,
vec::Vec,
};
pub trait FromBytesConvertible {
fn _from_be_bytes(bytes: Bytes) -> Self;
}
pub trait FromBytes {
fn from_bytes(bytes: Bytes) -> Self;
}
impl<T> FromBytes for T
where
T: FromBytesConvertible,
{
fn from_bytes(bytes: Bytes) -> Self {
Self::_from_be_bytes(bytes)
}
}
pub struct DataPoint {}
pub struct Payload {}
impl FromBytes for DataPoint {
fn from_bytes(bytes: Bytes) -> Self {
Self {}
}
}
impl Payload {
pub fn from_bytes(bytes: Bytes) {
let mut data_points = Vec::new();
data_points.push(DataPoint::from_bytes(bytes));
// let a = DataPoint::from_bytes(bytes);
// data_points.push(a);
}
}
pub fn main() {
Payload::from_bytes(Bytes::new());
}
Related Component
compiler
Problem
Let have a library (named redstone) with the lib file:
lib.sw
and the contract:
The library compiles properly, but the contract using the library does not. It leads to an error:
The code compiles in 0.63.1. It doesn't compile in 0.63.2 due to https://github.com/FuelLabs/sway/issues/6491.Steps
As above
Possible Solution(s)
Didn't find.
Notes
The repo with the issue:
https://github.com/redstone-finance/fuel-test-contract/tree/0.63.6
use
Installed components