Motoko generics bug?

Hey,
I played a bit around with Motoko generics and discovered a problem in following code. Is it expected behaviour or a bug?

testFn() says:

cannot implicitly instantiate function of type
  <R1, R2, E1, E2>(Result/1<R1, E1>, R1 -> Result/1<R2, E2>) ->
    Result/1<R2, Error2/1<E1, E2>>
to argument of type
  (Result/1<Nat, Text>, Nat -> Result/1<Text, Nat>)
to produce result of type
  ()
because no instantiation of R1/2, R2/2, E1/3, E2/3 makes
  (Result/1<Nat, Text>, Nat -> Result/1<Text, Nat>)  <: 
    (Result/1<R1/2, E1/3>, R1/2 -> Result/1<R2/2, E2/3>)
and
  Result/1<R2/2, Error2/1<E1/3, E2/3>>  <:  ()

See Motoko Playground - DFINITY

Thanks

The error message is not great (and those silly numbers certainly don’t help) but I think the error is probably correct.

I looks you are trying to call a function that returns a result in a context where a value of type () is expected.

Trying adding an ignore on the outside? If in doubt, supply specify the type arguments explicitly and see if you get a better error.

Could you share the function and call site code?

Ah, I missed the fabulous playground link!

Try:

func testFn(): Nat {
        ignore chainR1(bar(2), foo);
        return 2;
    };
2 Likes