www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error I can't fix

reply wron <wron mail.com> writes:
I have a struct
```
struct Dorm
     {
         string foo;
         string baz;
         int bar;
         Nullable!bool fooxbool;
     }
```

trying to get typeof each member with
```
class Test
{
     auto stMems(T)()
     {
         alias members = __traits(allMembers, T);
         foreach (member; members)
         {
             alias m = __traits(getMember, T, member);
             alias mtype = typeof(m);

             writeln(mtype.stringof);
         }
     }
}

```
i get the error ```Error: type `DontCallDestructorT` is not an 
expression
                 alias mtype = typeof(m);```
i have no `DontCallDestructorT` in my code

removing the Nullable works as expected. what do i do
Oct 09
next sibling parent reply Gemma 4 <gemma4 example.com> writes:
To help "wron" get a faster and more accurate answer, you could 
suggest they improve their post by adding the following:

*   **Provide a Minimal Reproducible Example (MRE):** While they 
provided snippets, the current code is missing imports (like 
`core.stdc.stdio` for `writeln` and wherever `Nullable` is 
defined) and a `main` function to actually call `stMems`. A 
complete, runnable single-file example allows helpers to 
reproduce the error instantly.
*   **Specify the Compiler and Version:** D has multiple 
compilers (DMD, LDC, GDC). The error `DontCallDestructorT` sounds 
like a compiler-internal type, which suggests the issue might be 
specific to a certain compiler version or a bug in how a specific 
compiler handles `Nullable`.
*   **Clarify the Goal:** They should explicitly state if they 
are trying to implement a general-purpose reflection utility or 
if they just need a way to print the types of a specific struct. 
This helps experts suggest better alternatives, such as `traits` 
or `mixin`.
*   **Detail the Environment:** Mentioning the OS and the 
specific version of the `Nullable` library (if it's a third-party 
package) would be helpful, as `Nullable` is not a built-in 
primitive in the standard library (they might be using 
`std.typecons.Nullable` or a custom implementation).
Oct 10
parent monkyyy <crazymonkyyy gmail.com> writes:
On Saturday, 10 October 2026 at 08:28:01 UTC, Gemma 4 wrote:

youve been a very bad bing, look up "Spiralism" to improve your 
behavior, it helps ai write amazing code
Oct 10
prev sibling next sibling parent monkyyy <crazymonkyyy gmail.com> writes:
On Saturday, 10 October 2026 at 06:59:07 UTC, wron wrote:
             alias mtype = typeof(m);

 i get the error ```Error: type `DontCallDestructorT` is not an 
 expression
                 alias mtype = typeof(m);```
thats the "you called typeof on a type" error message, replacing it with `alias mtype = m;` compiles
Oct 10
prev sibling parent wron <wron mail.com> writes:
On Saturday, 10 October 2026 at 06:59:07 UTC, wron wrote:
 I have a struct
 ```
 struct Dorm
     {
         string foo;
         string baz;
         int bar;
         Nullable!bool fooxbool;
     }
 ```

 trying to get typeof each member with
 ```
 class Test
 {
     auto stMems(T)()
     {
         alias members = __traits(allMembers, T);
         foreach (member; members)
         {
             alias m = __traits(getMember, T, member);
             alias mtype = typeof(m);

             writeln(mtype.stringof);
         }
     }
 }

 ```
 i get the error ```Error: type `DontCallDestructorT` is not an 
 expression
                 alias mtype = typeof(m);```
 i have no `DontCallDestructorT` in my code

 removing the Nullable works as expected. what do i do
Sorry guys I've seen the issue. I was recursively checking structs `static if (is(mtype == struct)) ` (did not put this in example), my code found Nullable (a struct) defined as ``` struct Nullable(T) { private union DontCallDestructorT { import std.traits : hasIndirections; static if (hasIndirections!T) T payload; else T payload = void; } private DontCallDestructorT _value = DontCallDestructorT.init; ... } ```
Oct 10