Bug 7273 – Tuples conversion assign

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-01-11T19:55:45Z
Last change time
2024-12-13T17:57:41Z
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#17536 →

Comments

Comment #0 by bearophile_hugs — 2012-01-11T19:55:45Z
Currently D tuples are library defined, and this probably gives some small restrictions. But I think well implemented built-in tuples should allow code like this, because here we are assigning an immutable value and copying it to a mutable one: import std.typecons: Tuple, tuple; Tuple!(int) foo() { immutable int x = 1; return tuple(x); } void main() {} DMD 2.058head: test.d(4): Error: cannot implicitly convert expression (tuple(1)) of type Tuple!(immutable(int)) to Tuple!(int) Because this code is allowed, and tuples too are values: int foo() { immutable int x = 1; return x; } void main() {}
Comment #1 by bearophile_hugs — 2012-01-12T10:54:55Z
Note this currently works: import std.typecons: Tuple, tuple; void main() { immutable int x = 1; Tuple!(int) y = tuple(1); }
Comment #2 by andrej.mitrovich — 2013-01-21T17:58:38Z
(In reply to comment #1) > Note this currently works: > > > import std.typecons: Tuple, tuple; > void main() { > immutable int x = 1; > Tuple!(int) y = tuple(1); > } I think you meant to write: Tuple!(int) y = tuple(x); Anyway this seems like more of a compiler issue than a library issue, because I don't think we can fix this in the library.
Comment #3 by b2.temp — 2020-07-01T18:31:02Z
associated key word is wrong. It's like saying that --- struct S(T){} static assert (is(S!(int) == S!(immutable(int))) --- would be a "rejects-valid".
Comment #4 by robert.schadek — 2024-12-13T17:57:41Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17536 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB