www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20161] New: Regression (2.088.0 beta) in compile-time

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 puremagic.com
          Reporter: n8sh.secondary 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()
{
}
---

--
Aug 23 2019