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
Comment #2 by k.hara.pg — 2016-05-09T23:21:39Z
Comment #3 by github-bugzilla — 2016-05-10T00:08:00Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ceff80f4df0d65e7e5023278420418d5e975f44b fix Issue 15974 - Spurious error: argument to mixin must be a string, not (expression()) of type string https://github.com/dlang/dmd/commit/7085fca5112bbfa018b15739e4b5c624d4ac4771 Merge pull request #5753 from 9rnsr/fix15974 Issue 15974 - Spurious error: argument to mixin must be a string, not (expression()) of type string
Comment #4 by github-bugzilla — 2016-10-01T11:46:55Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ceff80f4df0d65e7e5023278420418d5e975f44b fix Issue 15974 - Spurious error: argument to mixin must be a string, not (expression()) of type string https://github.com/dlang/dmd/commit/7085fca5112bbfa018b15739e4b5c624d4ac4771 Merge pull request #5753 from 9rnsr/fix15974