External Issue: converting custom object to JSON-formatted string fails

16945, “hokiegeek2”, “converting custom object to JSON-formatted string fails”, “2021-01-13T19:52:19Z”

Summary of Problem

The Chapel IOFormatter %jt formatter fails when using custom classes, throwing a compilation such as the following,
requiring the user to define custom records instead:

$CHPL_HOME/modules/standard/IO.chpl:3174: error: unresolved call 'borrowed Foo?.readThis(channel(false,dynamic,false))'
foo-example.chpl:5: note: this candidate did not match: Foo.readThis(f)
$CHPL_HOME/modules/standard/IO.chpl:3174: note: because method call receiver with type borrowed Foo?
foo-example.chpl:5: note: is passed to formal 'this: borrowed Foo'
$CHPL_HOME/modules/standard/IO.chpl:3174: note: try to apply the postfix ! operator to method call receiver
note: candidates are: object.readThis(f)
$CHPL_HOME/modules/internal/CString.chpl:229: note:                 c_string.readThis(x)
note: and 90 other candidates, use --print-all-candidates to see them

Steps to Reproduce

Source Code:

module FooExample {
    use IO;

    proc main() {
        class Foo {
           var name: string;
           var id: int;
           var isFoo: bool;

        var mem = try! openmem();
        try! mem.writer().write('{"name":"fooOne", "id":1, "isFoo":false}');
        var reader = try! mem.reader();
        var f = new Foo();
        try! reader.readf("%jt", f);
        try! writeln("Foo: %jt".format(f));

Compile command:
chpl foo-example.chpl

Execution command:

Associated Future Test(s):

Configuration Information

  • Output of chpl --version:
    chpl version 1.23.0
    Copyright 2020 Hewlett Packard Enterprise Development LP
    Copyright 2004-2019 Cray Inc.
    (See LICENSE file for more details)

  • Output of $CHPL_HOME/util/printchplenv --anonymize:
    machine info: Darwin hokiegeek2.home 19.6.0 Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64 x86_64
    CHPL_HOME: /Users/kjyost/development/chapel-1.23.0 *
    script location: /Users/kjyost/development/chapel-1.23.0/util/chplenv
    CHPL_TARGET_ARCH: x86_64
    CHPL_TARGET_CPU: native
    CHPL_COMM: none
    CHPL_TASKS: qthreads
    CHPL_TIMERS: generic
    CHPL_UNWIND: none
    CHPL_MEM: jemalloc
    CHPL_ATOMICS: cstdlib
    CHPL_GMP: none
    CHPL_HWLOC: hwloc
    CHPL_REGEXP: re2
    CHPL_LLVM: none

  • Back-end compiler and version, e.g. gcc --version or clang --version:
    Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
    Apple clang version 11.0.0 (clang-1100.0.33.8)
    Target: x86_64-apple-darwin19.6.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin