MCPcopy Index your code
hub / github.com/MadAppGang/dingo / generateBody

Method generateBody

pkg/codegen/lambda.go:108–123  ·  view source on GitHub ↗

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 { ... })

()

Source from the content-addressed store, hash-verified

106// - If has return type and single expression: adds implicit return
107// - Otherwise: uses body as-is (already has { ... })
108func (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.

Callers 1

GenerateMethod · 0.95

Calls 3

needsImplicitReturnMethod · 0.95
WriteMethod · 0.45

Tested by

no test coverage detected