Skip to content

Generic StorageKey impl fails to resolve get() on StorageMap, but concrete type works #7559

@bitzoic

Description

@bitzoic

When implementing methods on StorageKey<MyStorageType<T>> generically, calling .get() on a derived StorageKey<StorageMap<T, u64>> fails to compile.

However, the same code works when T is concretely specified (e.g. u64).

library;

use std::{
    hash::sha256,
};

pub struct MyStorageType<T> {}

// Fails to compile
impl<T> StorageKey<MyStorageType<T>> {
    fn internal_map(self) -> StorageKey<StorageMap<T, u64>> {
        StorageKey::new(self.slot(), self.offset(), sha256((self.field_id(), 2)))
    }

    fn foo(self, element: T) {
        let res = self.internal_map().get(element);
    }
}

// Compiles
impl StorageKey<MyStorageType<u64>> {
    fn internal_map(self) -> StorageKey<StorageMap<u64, u64>> {
        StorageKey::new(self.slot(), self.offset(), sha256((self.field_id(), 2)))
    }

    fn foo(self, element: u64) {
        let res = self.internal_map().get(element);
    }
}

Error:

"get(std::storage::storage_key::StorageKey<std::storage::storage_map::StorageMap<T, u64>>, T)" is not found for type "std::storage::storage_key::StorageKey<std::storage::storage_map::StorageMap<T, u64>>".

Testsed on forc v0.70.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilerGeneral compiler. Should eventually become more specific as the issue is triaged

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions