jhh671
August 23, 2022, 8:08pm
1
20491, "jhh67", "Reflection.getField on a managed class instance returns field of the wrapper instance", "2022-08-23T20:06:53Z"
opened 08:06PM - 23 Aug 22 UTC
type: Bug
area: Libraries / Modules
<!--
If you are filing an issue that is not a bug report, please feel free to e… rase
this template and describe the issue as clearly as possible.
-->
### Summary of Problem
<!--
What behavior did you observe when encountering this issue?
What behavior did you expect to observe?
Is this a blocking issue with no known work-arounds?
-->
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:**
```chapel
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:**
<!-- e.g. `./foo -nl 4`
If an input file is required, include it as well. -->
`./foo`
**Associated Future Test(s):**
<!-- Are there any tests in Chapel's test system that demonstrate this issue?
e.g. [`test/path/to/foo.chpl`](
https://github.com/chapel-lang/chapel/blob/main/test/path/to/foo.chpl
) #1234 -->
### 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`:
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
: