You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A generator function declaration nested inside another function has its yield type inferred as void, ignoring the yield expressions in its body. The same generator at the top level infers correctly.
Interpreter: prints [42] — runtime is unaffected (it ignores the inferred type).
Compiled:Error: The type 'System.Void' may not be used as a type argument. — the inferred Generator<void> becomes an invalid IEnumerator<System.Void> in IL.
Annotating the return type works around the inference but then hits the separate compiled-lowering bug #501:
function*g(): Generator<number>{yield42;}// nested → "Compile Error: Yield not supported in this context" (#501)
Contrast — top level infers correctly
lety=5;function*g(){yieldy;}// inferred Generator<number>console.log([...g()]);// [5] in both modes
Notes
Type-checker bug, independent of compilation: the inferred type is wrong (Generator<void> vs Generator<number>). It also produces spurious assignability errors, e.g. Type 'Generator<void>' is not assignable to type 'Generator<number>' when annotated as the latter.
Summary
A generator function declaration nested inside another function has its yield type inferred as
void, ignoring theyieldexpressions in its body. The same generator at the top level infers correctly.Repro
[42]— runtime is unaffected (it ignores the inferred type).Error: The type 'System.Void' may not be used as a type argument.— the inferredGenerator<void>becomes an invalidIEnumerator<System.Void>in IL.Annotating the return type works around the inference but then hits the separate compiled-lowering bug #501:
Contrast — top level infers correctly
Notes
Generator<void>vsGenerator<number>). It also produces spurious assignability errors, e.g.Type 'Generator<void>' is not assignable to type 'Generator<number>'when annotated as the latter.GeneratorArrowLifterlifts generator expressions to top-level declarations partly to stay on the working top-level inference path; this issue is one reason lifting them into a nested scope instead is not yet viable.