Bug 15993 – using mixin to specify 2 arguments for writefln results in unrecognized behavior
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-05-05T12:08:00Z
Last change time
2016-05-06T04:29:05Z
Assigned to
nobody
Creator
yosikawa
Comments
Comment #0 by yosikawa — 2016-05-05T12:08:46Z
following code throws.
string foo() {
return `123,"foo"`;
}
void main() {
writefln("%d %s", mixin(foo()));
}
object.Exception Incorrect format specifier for range: %d at C:\APP\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(2489)
DMD32 D Compiler v2.071.0
Comment #1 by mathias.lang — 2016-05-05T12:45:54Z
That's because it doesn't behaves as you expect it to.
What's mixed in is an expression, not a tuple. The first value is then discarded thanks to the coma operator.
Corrected code:
```
import std.typetuple;
import std.stdio;
string foo() {
return `AliasSeq!(123,"foo")`;
}
void main() {
writefln("%d %s", mixin(foo()));
}
```
Closing as invalid, as it behaves as expected.
Comment #2 by yosikawa — 2016-05-06T04:29:05Z
(In reply to Mathias Lang from comment #1)
> That's because it doesn't behaves as you expect it to.
>
> What's mixed in is an expression, not a tuple. The first value is then
> discarded thanks to the coma operator.
>
> Corrected code:
> ```
> import std.typetuple;
> import std.stdio;
>
> string foo() {
> return `AliasSeq!(123,"foo")`;
> }
> void main() {
> writefln("%d %s", mixin(foo()));
> }
> ```
>
> Closing as invalid, as it behaves as expected.
It works. Thanks for correction.