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.
()
| 773 | // Produces: var x TYPE; switch { case ...: x = value } |
| 774 | // Falls back to IIFE if type cannot be inferred. |
| 775 | func (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) |
no test coverage detected