public virtual void EndCurrentClosure(CurrentClosure cc) { if (cc != null){ //TODO: factor out the code for constructing the closure class, so that this elaborate setup is not necessary Checker checker = new Checker(null, this.typeSystem, null, null, null); checker.currentType = this.typeSystem.currentType = this.currentType; checker.currentMethod = this.currentMethod; Block oldBody = cc.Method.Body; TypeNode yieldType = this.typeSystem.GetStreamElementType(cc.Type, this.TypeViewer); cc.Method.Body = new Block(new StatementList(new Yield(new Literal(null, yieldType)))); checker.VisitMethod(cc.Method); Return ret = cc.Method.Body.Statements[0] as Return; Debug.Assert(ret != null); if (ret != null) { ConstructIterator ci = ret.Expression as ConstructIterator; Debug.Assert(ci != null); if (ci != null) { ci.Body = oldBody; cc.Method.Body.Scope = oldBody.Scope; this.VisitMethod(cc.Method); } } } }