MCPcopy
hub / github.com/MadAppGang/dingo / generateHumanLikeAssignment

Method generateHumanLikeAssignment

pkg/codegen/match.go:775–797  ·  view source on GitHub ↗

generateHumanLikeAssignment generates code for assignment context (x := match ...). Produces: var x TYPE; switch { case ...: x = value } Falls back to IIFE if type cannot be inferred.

()

Source from the content-addressed store, hash-verified

773// Produces: var x TYPE; switch { case ...: x = value }
774// Falls back to IIFE if type cannot be inferred.
775func (g *MatchCodeGen) generateHumanLikeAssignment() ast.CodeGenResult {
776 varName := g.Context.VarName
777 varType := g.Context.VarType
778
779 if varType == "" {
780 // IIFE fallback when type cannot be inferred
781 g.generateMatchIIFE()
782 return g.Result()
783 }
784
785 // Generate var declaration
786 g.Write(fmt.Sprintf("var %s %s\n", varName, varType))
787
788 // Generate switch with assignments
789 g.generateMatchSwitchWithAssignment(varName)
790
791 // Get result and move output to StatementOutput
792 result := g.Result()
793 result.StatementOutput = result.Output // Move to statement output
794 result.Output = nil // Clear expression output
795
796 return result
797}
798
799// generateHoistedMatch generates code for argument context (fn(match ...)).
800// Produces: var tmp TYPE; switch { case ...: tmp = value }; fn(tmp)

Callers 1

GenerateMethod · 0.95

Calls 4

generateMatchIIFEMethod · 0.95
ResultMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected