New Issue: Reflection.getField on a managed class instance returns field of the wrapper instance

20491, "jhh67", "Reflection.getField on a managed class instance returns field of the wrapper instance", "2022-08-23T20:06:53Z"

Summary of Problem

Note: I'm filing this as a bug because I think it's a bug, but if it's not then the Reflection module documentation should be updated.

Calling getField on a managed class instance doesn't work in the expected way. It is my understanding that managed class instances (e.g. borrowed, owned, shared) are "wrapped" in a management class instance. Calling getField returns the field of the wrapper instance, not the wrapped instance. I don't think that's what the developer wants. See the example program and output below.

Steps to Reproduce

Source Code:

use Reflection;

class Foo {
    var field0 = 42;
    var field1 = 117;
}

var foo = new Foo();

for param i in 0..<numFields(foo.type) {
    writeln(getFieldName(foo.type, i), " = ", getField(foo, i):string);
}

Output

field0 = borrowed Foo
field1 = {field0 = 42, field1 = 117}

Compile command:

chpl foo.chpl
Execution command:

./foo

Associated Future Test(s):

Configuration Information

  • Output of chpl --version:
chpl version 1.28.0 pre-release (b131550ff3)
Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)
  • Output of $CHPL_HOME/util/printchplenv --anonymize:
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: clang
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none *
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: none *
CHPL_HWLOC: bundled
CHPL_RE2: bundled
CHPL_LLVM: none *
CHPL_AUX_FILESYS: none
  • Back-end compiler and version, e.g. gcc --version or clang --version:
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
  • (For Cray systems only) Output of module list: