Skip to content

Some implementations still require imports #7330

@IGI-111

Description

@IGI-111

Some type implementations still require star imports to populate the trait map, ideally these should all be collected by the compiler without the need for user imports now that we have coherence checks.

Here's a minimal example:

main.sw

contract;

mod foobar;

use foobar::StorageFoobar;

storage {
    foo: StorageFoobar = StorageFoobar {},
}

impl Contract {
    fn foobar() {
        storage.foo.foobar();
    }
}

foobar.sw

library;

pub struct StorageFoobar {}

impl StorageKey<StorageFoobar> {
    pub fn foobar(self) {
        log("foobar");
    }
}

Produces the following error:

error
  --> /home/igi-111/Code/test_sway/src/main.sw:13:21
   |
11 | impl Contract {
12 |     fn foobar() {
13 |         storage.foo.foobar();
   |                     ^^^^^^ No method "foobar(StorageKey<StorageFoobar>)" found for type "StorageKey<StorageFoobar>".
14 |     }
15 | }
   |
____

  Aborting due to 1 error.
error: Failed to compile test_sway

Adding the following line to main.sw silences it:

use foobar::*; // this also imports implementations

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompiler: collectionEverything to do with graph collection, type collection, and the collection context.compiler: frontendEverything to do with type checking, control flow analysis, and everything between parsing and IRgenenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions