Bug 11387 – Tuple of dynamic array literal can't be immutable
Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-30T12:35:33Z
Last change time
2020-03-21T03:56:32Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-10-30T12:35:33Z
A low-priority enhancement suggestion:
import std.typecons: tuple;
void main() {
immutable t = tuple([1, 2]);
}
dmd 2.064beta3 gives:
test.d(3): Error: cannot implicitly convert expression (tuple([1, 2])) of type Tuple!(int[]) to immutable(Tuple!(int[]))
I presume built-in tuples could do this too.
To do this with Phobos-defined tuples, there should be a way to know that the input dynamic array is pure. I don't know if and how this can be done.