Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding entries to map of shared type results in an error #14713

Closed
ben-albrecht opened this issue Jan 3, 2020 · 3 comments · Fixed by #22100
Closed

Adding entries to map of shared type results in an error #14713

ben-albrecht opened this issue Jan 3, 2020 · 3 comments · Fixed by #22100

Comments

@ben-albrecht
Copy link
Member

ben-albrecht commented Jan 3, 2020

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: #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 (4f4e862)
@ben-albrecht
Copy link
Member Author

FYI map aficionado @dlongnecke-cray

@bradcray
Copy link
Member

bradcray commented Jan 3, 2020

@daviditen
Copy link
Member

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);

jabraham17 added a commit that referenced this issue Apr 27, 2023
Adds several new tests that are related to previous issues/bugs which
were filed and are no longer broken on main.

## New Tests
- `classes/delete-free/shared/shared-in-map-list.chpl` - Test for #14713
- `classes/deinitializers/owned-with-deinit.chpl` - Test for #12973
- `classes/fields/type-resolve-array-field.chpl` - Test for #11421
- `arrays/intents/in/defaultValueWithInIntent.chpl` - Test for  #11424
- `classes/errors/newWithoutParen.chpl` - Test for  #13201
- `functions/lambda/lambdaCapturing.chpl` - Test for #5544
- `library/standard/Map/getBorrowFromFunc.chpl` - Test for #14370

## Testing
- local testing

---

[Reviewed by @lydia-duncan ]

closes #14713
closes  #12973
closes  #11421
closes  #11424
closes #13201
closes #5544
closes #14370
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants