Index: lib/TableGen/TGParser.cpp =================================================================== --- lib/TableGen/TGParser.cpp +++ lib/TableGen/TGParser.cpp @@ -1084,6 +1084,14 @@ return nullptr; } Type = MHSt->getType(); + if (isa(Type)) { + TypedInit *RHSt = dyn_cast(RHS); + if (!RHSt) { + TokError("could not get type of !foreach list elements"); + return nullptr; + } + Type = RHSt->getType()->getListTy(); + } break; } case tgtok::XSubst: { Index: test/TableGen/foreach.td =================================================================== --- test/TableGen/foreach.td +++ test/TableGen/foreach.td @@ -7,12 +7,18 @@ // CHECK: "NAME" // CHECK: Defs + +// CHECK: def DX { +// CHECK: list x = ["0", "1", "2"]; +// CHECK: } + // CHECK: Jr // CHECK: Sr // Variables for foreach class decls { string name; + int num; } def Decls : decls; @@ -37,3 +43,9 @@ def Juniors : C; def Smiths : D<["NAME", "Jane Smith"]>; def Unprocessed : D; + +class X a> { + list x = !foreach(Decls.num, a, !cast(Decls.num)); +} + +def DX : X<[0, 1, 2]>;