Issue 12287 - infinite loop on std.traits.moduleName on templated struct member

https://d.puremagic.com/issues/show_bug.cgi?id=12287

Alternative fix of https://github.com/D-Programming-Language/dmd/pull/3346.