Chapel: Adding entries to map of shared type results in an error

Created on 3 Jan 2020  路  3Comments  路  Source: chapel-lang/chapel

Summary of Problem

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)

Steps to Reproduce

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.

Configuration Information

  • Output of chpl --version: chpl version 1.21.0 pre-release (4f4e86253a)
Libraries / Modules Bug

All 3 comments

FYI map aficionado @dlongnecke-cray

This seems potentially related to a number of other collection + managed class orthogonality issues:

  • #14361
  • #14367
  • #13096
  • #14362
  • #14423

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);
Was this page helpful?
0 / 5 - 0 ratings