initia-labs / movevm

Other
18 stars 11 forks source link

Can't infer type. #100

Open djm07073 opened 3 months ago

djm07073 commented 3 months ago

It looks like it have the same issue

struct Weight has copy, drop, store {
        bridge_id: u64,
        weight: Decimal128,
}

fun remove_vote(
        proposal: &mut Proposal,
        voting_power_used: u64,
        weights: vector<Weight>
    ) {
        let weight_sum = decimal128::zero();
        vector::for_each_ref(
            &weights,
            |w| {
                weight_sum = decimal128::add(&weight_sum, &w.weight); <---- cannot infer type. Unbound field 'weight'""
            }
        );
}
Vritra4 commented 3 months ago

link seems broken and invalid

djm07073 commented 3 months ago

now, i fix it

djm07073 commented 2 months ago

the code below builds successfully; a temporary workaround to avoid type inference errors.

inline fun use_user_vesting(_value: UserVesting) {} --> inline function to use explicit type

vector::for_each(
            user_vestings_cache, --> vector<UserVesting>
            |vesting| {
                use_user_vesting(vesting);  --> explicit type of UserVesting
                table::upsert(
                    user_vestings,
                    table_key::encode_u64(vesting.start_stage),
                    vesting
                );
                // .... other code logic
        );