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

Importing blob from canister #149

Closed
FloorLamp opened this issue Jul 20, 2020 · 2 comments · Fixed by dfinity/motoko#1744
Closed

Importing blob from canister #149

FloorLamp opened this issue Jul 20, 2020 · 2 comments · Fixed by dfinity/motoko#1744

Comments

@FloorLamp
Copy link
Contributor

Hi all! Hope everything has been going well, I've recently started building stuff with the SDK again and had a quick question.

I have two files:

// B.mo
actor B {
  public func get(): async Blob { "Hello" };
}
// A.mo
import B "canister:B";

type A = actor {
  get: () -> async Blob;
};

actor {
  let a: A = B;
}

This produces an error:

type error, expression of type
  actor {get : shared () -> async [Nat8]}
cannot produce expected type
  actor {get : shared () -> async Blob}

Is this expected? I can change A to use [Nat8], but I'm trying to keep the types the same. Thanks!

@nomeata
Copy link
Contributor

nomeata commented Jul 20, 2020

Yes, that is somewhat expected; in the Candid IDL (https://github.com/dfinity/candid/blob/master/IDL.md) blob and vec nat8 are aliases. I think there is work towards making that less annoying for blob (i.e. import it into motoko as Blob again), but in general this problem is unavoidable, and will surface with other types.

You can just write A.mo using Blob, but then you don’t get to use the nice type import feature…

@chenyan-dfinity
Copy link
Contributor

This is a bug, we have a PR to fix this in the compiler. The expected behavior is to import as a Blob type if the candid file says blob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants