January 05, 2023 [Issue 23601] New: [std.format] acceptedSpecs do match baseOfSpec | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23601 Issue ID: 23601 Summary: [std.format] acceptedSpecs do match baseOfSpec Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody@puremagic.com Reporter: jlourenco5691@gmail.com ```d import std; void main() { int i; "12.34".formattedRead!"%f"(i); } ``` This code sample compiles incorrectly to then fail at run time. The validation fails because it validates 'i' as a valid argument for the used spec. Any of [FfGgAaEe] counts as a valid base for any integral argument (int, bool, char, ...) and when checking acceptedSpecs at run time they do not match. It seems to me that baseOfSpec is the one in the wrong here, but the real issue is using the writing format to validate the reading format since 'int' can format into a 'float' but not the other way around. Moreover, 'a' is missing from acceptedSpecs, and all the upper case versions of spec are allowed by the 'write' version but not the 'read' alternative, which also leads to the run-time error `not supported with formatted read` instead of a compile-time assertion. Formatted read should validate the format specs with its own implementation if it differs this much from the 'write' version. -- |
Copyright © 1999-2021 by the D Language Foundation