[Issue 23643] [betterC] Better Error Message For CTFE GC Usage

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 23 04:41:17 UTC 2023


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

--- Comment #2 from Jack Stouffer <jack at jackstouffer.com> ---
(In reply to RazvanN from comment #1)
> Since the function is not a template, the compiler
> assumes that you want the object code for it and therefore nags you about
> the fact that you are doing illegal operations for betterC. If you want it
> to be ctfe only, just template it.

And we're just going to assume that everyone who tries to use betterC is going
to know this? Highly unlikely. I've been working with D for eight years; the
thought of templating the function never occurred to me. I just assumed there
was a bug in the compiler since I was only using the function in CTFE.

> What you are asking for is for the compiler to keep track of whether a
> function is called from ctfe or runtime contexts and if it is called only
> from ctfe to decide to either not output the object code or give some
> indication on how to fix this. But what if the person implementing
> myToString wants to call it from a different file and needs to have the
> object file working with betterC? Than the error is misleading.

Let me give you another example of something very similar that DMD already
does:

void main() {
    writeln("Hello!");
}

Error: `writeln` is not defined, perhaps `import std.stdio;` is needed?

Simple to read and gives the user the most likely solution to their problem. A
great error message! But, it's also possible that the user has their own
writeln function and they forgot to import that and not std.stdio.

A contrived example? No, this literally happened to me yesterday since I DO
have my own writeln. The fact the compiler gave me the wrong solution to my
problem did not bother me and was not an issue.

There is absolutely no downside to being a little more verbose in the error
messages. Obviously you can go too far towards the other end of the verbosity
spectrum. But what I'm asking here is for DMD to nudge the user along in most
likely the correct direction with a problem that's probably confusing.

--


More information about the Digitalmars-d-bugs mailing list