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

map doesn't work when value type is an owned class #14361

Closed
BryantLam opened this issue Oct 30, 2019 · 2 comments
Closed

map doesn't work when value type is an owned class #14361

BryantLam opened this issue Oct 30, 2019 · 2 comments

Comments

@BryantLam
Copy link

Bug. map doesn't work when value type is a class.

class MyInt {
    var x: int;
}

use Map;

var myMap = new map(string, owned MyInt);
# chpl version 1.21.0 pre-release (8b3bca92)
$CHPL_HOME/modules/standard/Map.chpl:96: In function 'init=':
$CHPL_HOME/modules/standard/Map.chpl:105: error: illegal lvalue in assignment

Also, I'm certain the remove function won't work either since I tried something similar on a bare associative array.

@bradcray
Copy link
Member

The reported behavior seems specific to the value type being an owned type. Making it a shared or unmanaged class makes the code above work. That said, I think there are other problems with non-nilable element types and maps, related to issue #14367 (i.e., I think the current map implementation works for cases like map(string, shared MyInt) today because of #14367, where it would stop working if/when #14367 was fixed).

Tagging @daviditen on this.

@daviditen
Copy link
Member

The thing that is causing this error is that the init= function takes its argument by const ref intent. Then it assigns all of the values (in this case none) in the rhs map to the lhs map, which for an owned class type modifies the const rhs to set the values to nil.

Changing the argument to use ref gets rid of the error by allowing the rhs to be modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants