[Issue 24567] New: In interpolation token strings: "$(expression)" is not treated as interpolation expression
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat May 25 15:41:43 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24567
Issue ID: 24567
Summary: In interpolation token strings: "$(expression)" is not
treated as interpolation expression
Product: D
Version: D2
Hardware: x86
OS: Windows
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: weltensturm at gmail.com
The following is supposed to fill the members of `test` with the content of
`assocarray`:
import std;
void main(){
struct Test {
int a;
}
Test test;
auto assocarray = [
"a": 1
];
static foreach(member; __traits(allMembers, Test)) {
mixin(iq{
writeln("$(member)");
test.$(member) = assocarray.get("$(member)", -1);
}.text);
}
writeln(test.a);
assert(test.a == 1);
}
Output:
$(member)
-1
core.exception.AssertError at .\test_token_interpolation.d(22): Assertion failure
It looks like token strings are "tokenized" before interpolation and not after,
which results in "string" tokens being completely ignored for interpolation.
--
More information about the Digitalmars-d-bugs
mailing list