Bug 15974 – Spurious error: argument to mixin must be a string, not (expression()) of type string
Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-04-30T00:59:00Z
Last change time
2016-10-01T11:46:55Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
iamthewilsonator
Comments
Comment #0 by iamthewilsonator — 2016-04-30T00:59:31Z
DMD64 D Compiler v2.070-devel-5123284
alias allDeviceFns = AliasSeq!("vkCreateSampler");
void loadDeviceFns(VkDevice d)
{
enum allFns = [allDeviceFns];
foreach(f;allFns)
{
mixin("%s = cast(typeof(%s)vkGetDeviceProcAddr(d,toStringz(\"%s\"))".format(f,f,f));
}
}
Gives two errors:
vk.d(1576): Error: variable f cannot be read at compile time
vk.d(1576): called from here: format("%s = cast(typeof(%s)vkGetDeviceProcAddr(d,toStringz(\"%s\"))", f, f, f)
vk.d(1576): Error: argument to mixin must be a string, not (format("%s = cast(typeof(%s)vkGetDeviceProcAddr(d,toStringz(\"%s\"))", f, f, f)) of type string
Comment #1 by k.hara.pg — 2016-05-09T13:24:01Z
I got a real minimized test case from incomplete sample code.
// test.d
string format(Args...)(string fmt, Args args)
{
return "";
}
void loadDeviceFns()
{
enum allFns = ["vkCreateSampler"];
foreach (f;allFns)
{
mixin("%s".format(f));
}
}
$ dmd -o- test
test.d(11): Error: variable f cannot be read at compile time
test.d(11): called from here: format("%s", f)
test.d(11): Error: argument to mixin must be a string, not (format("%s", f)) of type string