[Issue 1985] import expression should return ubyte[] not string

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 3 16:02:47 UTC 2021


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

hsteoh at quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WONTFIX                     |---

--- Comment #22 from hsteoh at quickfur.ath.cx ---
I use this feature from time to time, and I disagree that the primary use is to
import modules. That's confusing it with the other use of the `import` keyword
which has nothing to do with this feature, which is to read a file at
compile-time and process it at compile-time. You cannot use std.file.read at
compile-time, BTW.

One use case I have is to embed the contents of a file in a D program. (N.B.
not to be confused with loading a file at runtime.)

Since the compiler cannot possibly tell whether a file contains text or binary
data (or, for that matter, non-UTF-8 text data), it should not assume the data
can be sanely interpreted as `string`. Therefore, ubyte[] is the appropriate
return type, not `string`. (Though admittedly, this can be remedied with a cast
to ubyte[]. It's ugly, nonetheless.)

Finally, I disagree with closing this bug simply because it's old. Walter
himself often states that bugs should not be closed merely because they are old
or have not been receiving attention. A bug is a bug, regardless of age or
attention, and should be left open as long as the issue still exists. We should
not optimizing on metrics in place of actually improving the language /
compiler.  Unless Walter/Atila has explicitly decided that this issue will not
be fixed, it should remain open.

--


More information about the Digitalmars-d-bugs mailing list