June 14, 2011 Shared/const/immutable does not propagate to hash keys | ||||
---|---|---|---|---|
| ||||
shared int[int] AA; shared int[] arr; void main() { arr = AA.keys; } Error: cannot implicitly convert expression (AA.keys()) of type int[] to shared(int[]) Workaround: shared int[shared(int)] AA; shared int[] arr; void main() { arr = AA.keys; } Shouldn't shared propagate to the entire type? The same thing seems to happen with const and immutable: const int[const(int)] CONST = [1:1]; auto arr1 = CONST.keys; writeln(typeid(arr1)); // const(int)[] const int[int] NOTCONST = [1:1]; auto arr2 = NOTCONST.keys; writeln(typeid(arr2)); // int[] But .values doesn't suffer from the issue: import std.stdio; shared (int[int]) AA; void main() { auto arr1 = AA.keys; auto arr2 = AA.values; writeln(typeid(arr1)); // writes int[] writeln(typeid(arr2)); // writes shared(int)[] } |
Copyright © 1999-2021 by the D Language Foundation