Fix Issue 21456 - std.format does not accept enum member with string base type as template parameter#8029
Conversation
|
Thanks for your pull request and interest in making D better, @berni44! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8029" |
if that works then yes please |
| { | ||
| import std.array : appender; | ||
| import std.range.primitives : ElementEncodingType; | ||
| import std.traits : Unqual; |
There was a problem hiding this comment.
Why are these imports made public?
There was a problem hiding this comment.
Sorry, I needed that for stating the return type explicitly and forgot to undo this, when using auto.
…base type as template parameter
|
This is distinctly the wrong kind of generality. I am very sorry we missed the initial support for enum types derived from strings. No we don't need to support them. Whoever has those enums may as well call This pull should be undone and all support for enum strings should be deprecated. |
For me it is OK to revert this PR - I just tried to care about a bug and marking this bug as invalid would achieve my goals too. Anyway, I would like to understand what is wrong with enum types derived from strings? If I would have known this, I would have probably marked the issue immediately as invalid and gave a reason there. Maybe you can point me to a place, where this is explained? (Or explain it yourself in brief?) |
A great motive for ditching enum strings is that it avoids duplicated template instances. For instance void format(alias fmt)() { pragma(msg, fmt); }unittest {
format!("%s")();
enum Fmt : string { s = "%s" }
format!(Fmt.s)();
}prints meaning Does this hold for enum's based on other types aswell such as aggregates, @andralex ? |
|
I am wondering, why is Having |
Don't know. It was introduced in #5288 and not changed since. At least no unittest complains, when I replace it with |
|
CC @ntrel |
No real reason. I think I just used alias whilst working on the change as it's more flexible, then never thought to tighten it to string before submitting. |
This is probably the right answer. It should work with anything that currently works, except A good first step might be reverting this, and seeing if replacing |
|
Note that we still would need to deprecate if we did move to accepting a string directly. |
|
There are more format specificers being |
Don't know if it wouldn't be better to have to return type just being
auto...