Why is this Compiling error happening for v0.64?

Error:

104 | 
105 | //
106 | impl<T> Option<T> {
    |      ^ Cannot infer type for type parameter "T". Insufficient type information provided. Try annotating its type.
107 |     // Querying the contained values
108 |     //
    |

My toolchain:

Installed toolchains
--------------------
latest-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
nightly-2024-05-28-x86_64-unknown-linux-gnu
testnet-x86_64-unknown-linux-gnu

active toolchain
----------------
latest-x86_64-unknown-linux-gnu (default)
  forc : 0.64.0
    - forc-client
      - forc-deploy : 0.64.0
      - forc-run : 0.64.0
    - forc-crypto : 0.64.0
    - forc-debug : 0.64.0
    - forc-doc : 0.64.0
    - forc-fmt : 0.64.0
    - forc-lsp : 0.64.0
    - forc-tx : 0.64.0
    - forc-wallet : 0.9.1
  fuel-core : 0.36.0
  fuel-core-keygen : 0.36.0

fuels versions
--------------
forc : 0.66
forc-wallet : 0.66.5

There won’t be any error if using forc 0.60.0+nightly.20240528.4fe6f1ed51, why though:

//fuel-toolchain.toml
[toolchain]
channel = "nightly-2024-05-28"

[components]
forc = "0.60.0+nightly.20240528.4fe6f1ed51"
fuel-core = "0.26.0"

My code:

script;

use libraries::{AMM, Exchange, data_structures::Asset, data_structures::PreviewSwapInfo };

/// Determines the type of input error.
enum InputError {
    /// The number of assets in the swap is less than 2.
    RouteTooShort: (),
}

/// Determines the type of swap error.
enum SwapError {
    /// The amount bought is less than the minimum output amount.
    ExcessiveSlippage: u64,
    /// The exchange for this asset pair could not be found.
    PairExchangeNotRegistered: (AssetId, AssetId),
}

configurable {
    /// The ContractId of the AMM contract.
    AMM_ID: b256 = 0x07b88ef9667910ca5b107df63ca2171b5dfffdcab8f07e219971876e46dce9de,
}

/// Swaps assets along a route by specifying exact output for each swap.
///
/// # Arguments
///
/// * `assets`: [Vec<AssetId>] - The assets along the swap route.
/// * `output_amount`: [u64] - The desired amount of the output asset.
/// * `maximum_input_amount`: [u64] - The maximum amount of the input asset.
/// * `deadline`: [u64] - The limit on block height for operation.
///
/// # Returns
///
/// * `u64`: The amount of the input asset that was sold.
///
/// # Reverts
///
/// * When `assets.len()` is less than two.
/// * When the exchange contract has not been registered in the AMM.
/// * When the amount of the sold asset is greater than `maximum_input_amount`.
fn main(
    assets: Vec<AssetId>,
    output_amount: Option<u64>,
    maximum_input_amount: Option<u64>,
    deadline: u64,
) -> u64 {
    require(assets.len() >= 2, InputError::RouteTooShort);

    let amm_contract = abi(AMM, AMM_ID);
    let mut latest_sold_wrap: Option<u64> = output_amount;

    let mut latest_sold = output_amount.unwrap();
    
    if maximum_input_amount.is_some(){
        require(
            latest_sold <= maximum_input_amount.unwrap(),
            SwapError::ExcessiveSlippage(latest_sold),
        );
    }
    // start swapping by buying the last asset in the route.
    let mut bought_asset_index = assets.len() - 1;

    // swap subsequent asset pairs along route.
    while bought_asset_index > 0 {
        let asset_pair = (
            assets.get(bought_asset_index - 1).unwrap(),
            assets.get(bought_asset_index).unwrap(),
        );

        // get the exchange contract id of asset pair.
        let exchange_contract_id = amm_contract.pool {
            gas: 100_000,
        }(asset_pair);

        require(
            exchange_contract_id
                .is_some(),
            SwapError::PairExchangeNotRegistered(asset_pair),
        );  
        let exchange_contract = abi(Exchange, exchange_contract_id.unwrap().into());

        let preview: PreviewSwapInfo = exchange_contract.preview_swap_exact_output(Asset::new(asset_pair.1, latest_sold));
        let sell_amount = preview.other_asset.amount;

        // swap by specifying the exact amount to buy.
        latest_sold = exchange_contract.swap_exact_output {
            gas: 10_000_000,
            coins: sell_amount, // forward coins of asset to sell.
            asset_id: asset_pair.0.into(), // identifier of asset to sell.
        }(latest_sold_wrap, deadline);

        bought_asset_index -= 1;
    }

    latest_sold
}

Can you try updating the forc versions and toolchain? also, put the latest versions in fuel-toolchain.toml forc should be >0.64.0 and toolchain should be nightly. Please use this docs to upgrade Installation | Fuel Docs

Hi still doesn’t work. Same error.

[toolchain]
channel = "nightly"

[components]
forc = "0.64.0"
fuel-core = "0.36.0"

Need to update:
curl https://install.fuel.network | sh
update fuel

1 Like

Updated it and removed fuel-toolchain.toml to use the latest version. Doesn’t work either.

Installed toolchains
--------------------
latest-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
nightly-2024-05-28-x86_64-unknown-linux-gnu
testnet-x86_64-unknown-linux-gnu

active toolchain
----------------
latest-x86_64-unknown-linux-gnu (default)
  forc : 0.65.2
    - forc-client
      - forc-deploy : 0.65.2
      - forc-run : 0.65.2
    - forc-crypto : 0.65.2
    - forc-debug : 0.65.2
    - forc-doc : 0.65.2
    - forc-fmt : 0.65.2
    - forc-lsp : 0.65.2
    - forc-tx : 0.65.2
    - forc-wallet : 0.10.0
  fuel-core : 0.37.1
  fuel-core-keygen : 0.37.1

fuels versions
--------------
forc : 0.66.6
forc-wallet : 0.66.6

what is the output: systemctl status fueld ?

Terminal Returns:

104 | 
105 | //
106 | impl<T> Option<T> {
    |      ^ Cannot infer type for type parameter "T". Insufficient type information provided. Try annotating its type.
107 |     // Querying the contained values
108 |     //
    |

is there fuel-core-keygen?

Yes, please refer above.

Can you please share your codebase, i will look into it locally

Hi @Nazeeh21, I have reported this bug in Github and is being fixed. Can I redirect you to another issue? When I run cargo test

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.