I am running into an issue with the Motoko compiler (dfx 0.8.4) when importing two canisters and calling functions on each.
Canister A imports canisters B and C.
import B "canister:B”;
import C "canister:C”;
When calling a function of B, the compiler incorrectly expects a different return type that only exists in a function of C.
When inspecting B.did and C.did, the return type of the function I am calling in B has the same autogenerated type name (Result_2) as the return type in C that the compiler is expecting.
B.did
type Result_2 =
variant {
err: text;
ok: text;
};
C.did
type Result_2 =
variant {
err: text;
ok: opt vec SomeType;
};
Error:
Stderr:
/src/Post/main.mo:196.59-196.146: type error [M0096], expression of type
Result_2 = {#err : Text; #ok : ?[SomeType]}
cannot produce expected type
{#err : Text; #ok : Text}
So, with multiple canister imports, it appears that the compiler is expecting the incorrect return types of functions when they have the same autogenerate type names in the did files.
I should also mention that I started using Text as the error type because I ran into the same issue with multiple variant types for defining errors.
This is currently a roadblock and the only solution I know of is to remove one of the canister imports. If anyone knows of another solution, please advise me. Thank you!