Adding to a map with a value of shared
type, results in an error in Map.chpl
.
My current work-around is to stick to unmanaged
for now. (owned
and borrowed
have separate issues: https://github.com/chapel-lang/chapel/issues/14712)
Source Code:
use Map;
var children: map(string, shared Node?);
var n = new shared Node();
children.add('key', n);
class Node { }
Error message:
map-add-bug.chpl:5: error: value from coercion passed to const ref formal 'v'
$CHPL_HOME/modules/standard/Map.chpl:294: note: to function 'add' defined here
$CHPL_HOME/modules/standard/Map.chpl:294: note: default intent for shared Node? has changed from `in` to `const ref`
I found that this can be fixed by modifying the add
signature in Map.chpl
:
proc add(k: keytype, v: valtype): bool { ... }
changed to:
proc add(k: keytype, in v: valtype): bool { ... }
However, I have not done testing beyond my user code with this fix.
chpl --version
: chpl version 1.21.0 pre-release (4f4e86253a)FYI map aficionado @dlongnecke-cray
This seems potentially related to a number of other collection + managed class orthogonality issues:
I'm tracking this list in https://github.com/Cray/chapel-private/issues/643 and have added this issue to that list.
The coercion from Node
to Node?
when passing it to add
by const ref
intent is causing this error. Adding a temp that is nillable and going through that works around it.
var nillableN: Node? = n;
children.add('key', nillableN);