generateBody generates the function body. For expression bodies: - Wraps in { return ... } For block bodies: - If has return type and single expression: adds implicit return - Otherwise: uses body as-is (already has { ... })
()
| 106 | // - If has return type and single expression: adds implicit return |
| 107 | // - Otherwise: uses body as-is (already has { ... }) |
| 108 | func (g *LambdaCodeGen) generateBody() { |
| 109 | if g.expr.IsBlock { |
| 110 | // Block body - check if we need implicit return |
| 111 | if g.expr.ReturnType != "" && g.needsImplicitReturn() { |
| 112 | g.writeBlockWithImplicitReturn() |
| 113 | } else { |
| 114 | // Pass through as-is |
| 115 | g.Write(g.expr.Body) |
| 116 | } |
| 117 | } else { |
| 118 | // Expression body - wrap in { return ... } |
| 119 | g.Write("{ return ") |
| 120 | g.Write(g.expr.Body) |
| 121 | g.Write(" }") |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // needsImplicitReturn checks if a block body needs an implicit return. |
| 126 | // Returns true if the block contains a single expression without return/if/for/switch. |
no test coverage detected