Bug 9133 – std.datetime: Cannot implicitly convert const(SysTime) to SysTime
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-10T01:38:00Z
Last change time
2015-07-07T08:50:47Z
Assigned to
nobody
Creator
bugzilla
Comments
Comment #0 by bugzilla — 2012-12-10T01:38:37Z
Test case:
import std.datetime;
const SysTime a;
SysTime b = a;
Error: cannot implicitly convert expression (a) of type const(SysTime) to SysTime
This is extremely surprising to me, as I would expect SysTime to have value semantics. I suppose this has to do with the timezone field?
If this problem is unavoidable, I think that SysTime should either have a copy/dup method, or at the very least it should be noted in the documentation whether it is safe to cast it to mutable.
Comment #1 by issues.dlang — 2012-12-10T02:09:16Z
It's an issue with dmd. For whatever reason, it won't let you assign a SysTime to const or immutable even though everything in it should be convertible to const. The fact that it contains reference to a class screws it up, even though it's immutable. You have to have a postblit to fix it, but you can't have a const or immutable postblit, so you can't copy it if it's const or immutable. This problem occurs with every single struct which has reference types in it aside from dynamic arrays. It's something that needs to be solved in the language and the compiler. So, it comes down to two things:
1. dmd should be smart enough to realize that it doesn't need a postblit constructor in this case (because the class is immutable), but it isn't.
2. postblit is inherently broken with regards to const and immutable. This is a huge problem that goes way beyond just std.datetime.
Comment #2 by issues.dlang — 2015-07-07T08:50:47Z
I don't know when this was fixed, but it works with the current dmd master.