Thread overview
[Issue 20847] confusing compiler error message when compiling PosixTimeZone.getTimeZone
May 19, 2020
mw
May 21, 2020
RazvanN
May 19, 2020
https://issues.dlang.org/show_bug.cgi?id=20847

--- Comment #1 from mw <mingwu@gmail.com> ---
This file? it's there:

$ ls -l /usr/share/zoneinfo/America/New_York
lrwxrwxrwx 1 root root 13 Sep 20  2019 /usr/share/zoneinfo/America/New_York ->
../posixrules

--
May 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20847

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |INVALID

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
This is not a bug. Initializers of class members need to be evaluable at compile time so the compiler tries to interpret the body of function getTimeZone at compile time. Since lstat/GetFileAttributesW are not D functions that have available code, you end up with the (correct) error that is currently outputted. You can call those functions at runtime because you the object code is linked and you have no problems, but interpretation needs the source code.

Fortunately, there is a standard way of doing this, using a class static constructor [1] that were created for exactly this purpose:

import std.datetime.timezone;

class T {
    enum NEW_YORK_TIMEZONE = "America/New_York";
    public static const PosixTimeZone _timeZoneInfo;

    static this()
    {
        _timeZoneInfo = PosixTimeZone.getTimeZone(NEW_YORK_TIMEZONE);
    }
}

Closing this as invalid.

[1] https://dlang.org/spec/class.html#static-constructor

--
July 03
https://issues.dlang.org/show_bug.cgi?id=20847

Chance Snow <git@chancesnow.me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |git@chancesnow.me
         Resolution|INVALID                     |---

--- Comment #3 from Chance Snow <git@chancesnow.me> ---
I am experiencing this issu and because I cannot use GDC, it is impossible to diagnose the source of "`lstat` cannot be interpreted at compile time [...]".

Please provide a call trace in the error message in DMD as does GDC.

--
July 23
https://issues.dlang.org/show_bug.cgi?id=20847

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--