Thread overview
need solution for find error : Error: `TypeInfo` cannot be used with -betterC
Jul 22, 2022
test123
Jul 22, 2022
test123
Jul 22, 2022
test123
Jul 22, 2022
Paul Backus
Jul 22, 2022
user1234
Jul 22, 2022
ryuukk_
July 22, 2022

some time a huge project build throw error: "Error: TypeInfo cannot be used with -betterC"

and it work before some days ago, there is no array allow but throw this error. no location information (file and line).

We need solution to improve the error message so people can find where to fix it.

July 22, 2022

On Friday, 22 July 2022 at 06:06:09 UTC, test123 wrote:

>

some time a huge project build throw error: "Error: TypeInfo cannot be used with -betterC"

and it work before some days ago, there is no array allow but throw this error. no location information (file and line).

We need solution to improve the error message so people can find where to fix it.

"ldc2/bin/../import/std/array.d(1116): Error: TypeInfo cannot be used with -betterC",

July 22, 2022

On Friday, 22 July 2022 at 06:06:09 UTC, test123 wrote:

>

some time a huge project build throw error: "Error: TypeInfo cannot be used with -betterC"

and it work before some days ago, there is no array allow but throw this error. no location information (file and line).

We need solution to improve the error message so people can find where to fix it.

not my first time find this problem. but this time is not make no sense.

import std.bitmanip : bitfields;

enum UserRole : ubyte {
    None        = 0,
}

alias UserIdT = ushort;

enum BIT_COUNT    = 30;
enum MAX_COUNT    = 2 ^^ BIT_COUNT;

struct UserSession {
    union {
        ulong   uint64;
        mixin(bitfields!(
                UserIdT,    "user_id",  16,
                UserRole,    "user_role",   2,
                uint,       "login_count", BIT_COUNT,
            ));
    }
}

extern(C) void main(){
 	
}

there is no array related code, but throw TypeInfo error

July 22, 2022

On Friday, 22 July 2022 at 06:16:56 UTC, test123 wrote:

>

there is no array related code, but throw TypeInfo error

bitfields probably uses an array in CTFE somewhere. Due to limitations of the current compiler, BetterC code is not allowed to use arrays even in code that is only executed at compile time (bug report: https://issues.dlang.org/show_bug.cgi?id=19268).

July 22, 2022

On Friday, 22 July 2022 at 06:16:56 UTC, test123 wrote:

>

On Friday, 22 July 2022 at 06:06:09 UTC, test123 wrote:

>

some time a huge project build throw error: "Error: TypeInfo cannot be used with -betterC"

and it work before some days ago, there is no array allow but throw this error. no location information (file and line).

[...]
there is no array related code, but throw TypeInfo error

your bitfield size is not good, which leads to a to!string in a static assert that uses array under the hood. With a good size,

struct UserSession {
    union {
        ulong   uint64;
        mixin(bitfields!(
                UserIdT,    "user_id",  16,
                UserRole,    "user_role",   2,
                uint,       "login_count", BIT_COUNT,
                uint, "pad", 16
            ));
    }
}

there's another error in myToString()

>

Error: array concatenation of expression cast(const(char)[])s ~ (n > 4294967295LU ? "UL" : "U") requires the GC which is not available with -betterC

what's unfair is that both problems are caused by static evaluation/CTFE.
That's compiler bugs. The compiler thinks that the code will be used at run-time while it is only statically evaluated, hence there's no betterC restrictions.
For myToString(), maybe also that pragma(ctfe) would be required.

I see no solution excepted the one that is to write a simpler, stripped down, version of bitfields.

July 22, 2022

Alternatively you can grab latest DMD night and use builtin bitfield feature

-preview=bitfields

https://dlang.org/changelog/pending.html#bitfields