Bug 20161 – Regression (2.088.0 beta) in compile-time evaluation of immutable static fields

Status
RESOLVED
Resolution
WORKSFORME
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-23T23:03:53Z
Last change time
2020-03-21T03:56:35Z
Assigned to
No Owner
Creator
Nathan S.

Comments

Comment #0 by n8sh.secondary — 2019-08-23T23:03:53Z
This code works with DMD 2.067.1 through 2.087.1 but fails with DMD 2.088.0-beta.1-master-ede5969. https://run.dlang.io/is/rawZ1B --- final class Bool { immutable bool value; alias value this; this(bool b) nothrow pure @safe { this.value = b; } } struct ConstBool { private immutable Bool _b; @property Bool _uncast() const nothrow pure @trusted { // It is safe to convert an immutable Bool to a mutable Bool // because even a mutable Bool has no mutable fields (and // cannot have any because Bool is a final class). return cast() this._b; } alias _uncast this; this(const Bool b) nothrow pure @trusted { // Can convert mutable bool to immutable by same logic as above. this._b = cast(immutable) b; } // https://forum.dlang.org/post/[email protected] T opCast(T)() const { static if (is(bool : T)) return _b.value; else return cast(T) this._uncast; } } immutable TRUE = ConstBool(new Bool(true)), FALSE = ConstBool(new Bool(false)); static assert(!FALSE); // Works in DMD 2.067.1 through 2.087.1 but in DMD 2.088.0-beta.1-master-ede5969 fails with "Error: expression Bool(false) is not constant" static assert(!!TRUE); // Works in DMD 2.067.1 through 2.087.1 but in DMD 2.088.0-beta.1-master-ede5969 fails with "Error: expression Bool(true) is not constant" void main() { } ---
Comment #1 by b2.temp — 2019-11-21T16:13:08Z
working in stable