Reference to Sequence of ForEachStmt

I'm playing around with the implementation for buildArray of @resultBuilder. I'm trying to make a small change (at least I think it's small :rofl:) and pass the for loop sequence to the buildArray.

I tried to build a reference to the sequence and pass it but it fails with Assertion failed: (!getDeclContext()->isLocalContext() && "not a global variable!"). I made the following modification:

auto sequence = forEachStmt->getSequence();
auto sequenceType = cs->getType(sequence);
auto *sequenceVar = buildVar(sequence->getLoc());

cs->setType(sequenceVar, sequenceType);

auto sequenceVarRef = buildVarRef(sequenceVar, sequence->getEndLoc());

auto buildArrayCall = buildCallIfWanted(endLoc, ctx.Id_buildArray, { sequenceVarRef }, { Identifier() });

Am I at least on the right path to make it work or am I completely wrong and it's something much more difficult to achieve?

Terms of Service

Privacy Policy

Cookie Policy