roc icon indicating copy to clipboard operation
roc copied to clipboard

Abilities build error when importing module

Open JRI98 opened this issue 9 months ago • 0 comments

The following program builds but gives the error:

This expression has a type that does not implement the abilities it's expected to:

11│      when Str.fromUtf8 (Encode.toBytes {} MyModule.jsonCoder) is
                                              ^^^^^^^^^^^^^^^^^^

The type Json does not fully implement the ability EncoderFormatting.

main.roc

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
    json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.9.0/JI4BuuOuWnD1R3Xcx-F8VrWdj-LM_FfDRB00ekYjIIQ.tar.br",
}

import MyModule
import pf.Stdout
import pf.Stderr

main =
    when Str.fromUtf8 (Encode.toBytes {} MyModule.jsonCoder) is
        Ok o ->
            Stdout.line! o

        Err err ->
            Stderr.line! (Inspect.toStr err)

MyModule.roc

module [jsonCoder]

import json.Json

jsonCoder = Json.utf8With { fieldNameMapping: SnakeCase, skipMissingProperties: Bool.true }

Note: this error does not appear if the contents of MyModule.roc are moved to main.roc.

JRI98 avatar May 09 '24 15:05 JRI98