Type inference for yield with scope