[Issue 20161] New: Regression (2.088.0 beta) in compile-time evaluation of immutable static fields

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 23 23:03:53 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20161

          Issue ID: 20161
           Summary: Regression (2.088.0 beta) in compile-time evaluation
                    of immutable static fields
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: n8sh.secondary at hotmail.com

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/eicpsjarvxvahknluqwu@forum.dlang.org
    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()
{
}
---

--


More information about the Digitalmars-d-bugs mailing list