Bug 19169 – [betterC] bogus TypeInfo error for `enum string[] a = ["a"]; auto aa = a;`

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2018-08-14T13:16:24Z
Last change time
2023-01-15T04:30:57Z
Keywords
betterC
Assigned to
No Owner
Creator
Nicholas Wilson

Comments

Comment #0 by iamthewilsonator — 2018-08-14T13:16:24Z
extern(C) void main() { enum string[] a = ["a"]; auto aa = a; } > onlineapp.d(3): Error: TypeInfo cannot be used with -betterC
Comment #1 by iamthewilsonator — 2018-08-14T13:19:12Z
Interestingly enum a = ["a"]; __gshared auto aa = a; extern(C) void main() {} Passes compilation just fine.
Comment #2 by slavo5150 — 2018-08-14T13:27:01Z
The problem is here: https://github.com/dlang/dmd/blob/48726c875fbfe16fd93051570d149e893d2dc3dc/src/dmd/e2ir.d#L5047-L5050 --- // call _d_arrayliteralTX(ti, dim) e = el_bin(OPcall, TYnptr, el_var(getRtlsym(RTLSYM_ARRAYLITERALTX)), el_param(el_long(TYsize_t, dim), getTypeInfo(ale.loc, ale.type, irs))); --- The compiler is generating a call to `_d_arrayliteralTX` in druntime: https://github.com/dlang/druntime/blob/9a8edfb48e4842180c706ee26ebd8edb10be53f4/src/rt/lifetime.d#L2279 That runtime hook requires a `TypeInfo` parameter. One solution would be to replace `_d_arrayliteralTX` with a template and a compile-time type parameter, but this issue does beg the question why it is even calling `_d_arrayliteralTX` in the first place.
Comment #3 by iamthewilsonator — 2018-08-14T13:28:27Z
At the very least the error message should not suck.
Comment #4 by iamthewilsonator — 2018-08-14T13:30:08Z
This triggers for ints as well. extern(C) void main() { auto a = [1]; } same problem.
Comment #5 by iamthewilsonator — 2018-08-14T13:31:24Z
extern(C) void main() { immutable a = [1]; } works fine though.
Comment #6 by bugzilla — 2023-01-15T04:30:57Z
(In reply to Nicholas Wilson from comment #0) > extern(C) void main() { > enum string[] a = ["a"]; > auto aa = a; // line 3 > } Now produces the error: test.d(3): Error: expression `["a"]` uses the GC and cannot be used with switch `-betterC` which is not bad. If we write this: extern(C) void main() { enum string[] a = ["a"]; auto aa = a[0]; } it compiles without complaint. As far as I can see, this is expected behavior. The former produces the error because ["a"] has to be allocated somewhere at runtime, but with no GC, where should it be placed? > At the very least the error message should not suck. This condition is met, so I shall mark this as fixed.