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

Trait: "method dummy and was not properly replaced" error in 0.63.6 #6572

Open
Lukasz2891 opened this issue Sep 20, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen

Comments

@Lukasz2891
Copy link

Lukasz2891 commented Sep 20, 2024

Related Component

compiler

Problem

Let have a library (named redstone) with the lib file:

lib.sw

library;

use std::{bytes::Bytes};

pub trait FromBytesConvertible {
    fn size() -> u64;
    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 {
        assert(bytes.len() <= Self::size());

        let mut bytes = bytes;

        while (bytes.len() < Self::size()) {
            bytes.insert(0, 0u8);
        }

        Self::_from_be_bytes(bytes)
    }
}


pub struct DataPoint {}
pub struct DataPackage {}
pub struct Payload {}

pub fn make_data_package(bytes: Bytes) -> (DataPackage, u64) {
    let mut data_points = Vec::new();
    data_points.push(DataPoint::from_bytes(bytes));

    return (DataPackage {}, 0);
}

impl FromBytes for DataPoint {
    fn from_bytes(bytes: Bytes) -> Self {
        Self {
        }
    }
}

impl Payload {
    pub fn from_bytes(bytes: Bytes) -> Self {
        let mut data_packages = Vec::new();
        let (data_package, _) = make_data_package(bytes);
        data_packages.push(data_package);

        Self {}
    }
}

pub fn process_input(bytes: Bytes) -> (Vec<u256>, u64) {
    let payload = Payload::from_bytes(bytes);

    (Vec::new(), 0)
}

and the contract:

contract;

use std::{
    bytes::Bytes,
    vec::Vec,
};
use redstone::process_input;

abi RedStoneCore {
    fn get_prices(feed_ids: Vec<u256>, payload: Bytes) -> (Vec<u256>, u64);
}

impl RedStoneCore for Contract {
    fn get_prices(feed_ids: Vec<u256>, payload_bytes: Bytes) -> (Vec<u256>, u64) {
        process_input(payload_bytes)
    }
}

The library compiles properly, but the contract using the library does not. It leads to an error:

error
 --> /[Redacted]/redstone-fuel-sdk/src/lib.sw:7:8
  |
5 | 
6 |     fn size() -> u64;
7 |     fn _from_be_bytes(bytes: Bytes) -> Self;
  |        ^^^^^^^^^^^^^^ Internal compiler error: Method _from_be_bytes_70 is a trait method dummy and was not properly replaced.
Please file an issue on the repository and include the code that triggered this error.
8 | }

The code compiles in 0.63.1. It doesn't compile in 0.63.2 due to #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

make build

Installed components

active toolchain
----------------
nightly-aarch64-apple-darwin (default)
  forc : 0.63.6+nightly.20240919.10a78a7624
    - forc-client
      - forc-deploy : 0.63.6+nightly.20240919.10a78a7624
      - forc-run : 0.63.6+nightly.20240919.10a78a7624
    - forc-crypto : 0.63.6+nightly.20240919.10a78a7624
    - forc-debug : 0.63.6+nightly.20240919.10a78a7624
    - forc-doc : 0.63.6+nightly.20240919.10a78a7624
    - forc-fmt : 0.63.6+nightly.20240919.10a78a7624
    - forc-lsp : 0.63.6+nightly.20240919.10a78a7624
    - forc-tx : 0.63.6+nightly.20240919.10a78a7624
    - forc-wallet : 0.9.0+nightly.20240919.29d9b25c2c
  fuel-core : 0.36.0+nightly.20240919.408c468098
  fuel-core-keygen : not found
@Lukasz2891 Lukasz2891 added bug Something isn't working triage This issue was opened with a template and needs to be triaged by code owners. labels Sep 20, 2024
@IGI-111 IGI-111 self-assigned this Sep 30, 2024
@IGI-111 IGI-111 added compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen and removed triage This issue was opened with a template and needs to be triaged by code owners. labels Sep 30, 2024
@IGI-111
Copy link
Contributor

IGI-111 commented Sep 30, 2024

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.

@IGI-111
Copy link
Contributor

IGI-111 commented Sep 30, 2024

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());
}

@IGI-111 IGI-111 assigned esdrubal and unassigned IGI-111 Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

No branches or pull requests

3 participants