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

Method generateGroupedCases

pkg/codegen/match.go:205–228  ·  view source on GitHub ↗

generateGroupedCases groups arms by pattern type and generates cases. This is critical for handling guarded patterns: - Multiple arms for the same constructor become if/else chain in one case - Avoids duplicate case clauses which are illegal in Go

(typeSwitch bool)

Source from the content-addressed store, hash-verified

203// - Multiple arms for the same constructor become if/else chain in one case
204// - Avoids duplicate case clauses which are illegal in Go
205func (g *MatchCodeGen) generateGroupedCases(typeSwitch bool) {
206 // Group arms by their case key (type name for constructors, "default" for wildcards)
207 groups := make(map[string]*armGroup)
208 var order []string // Preserve order
209
210 for _, arm := range g.Match.Arms {
211 key := g.getPatternCaseKey(arm.Pattern)
212
213 if _, exists := groups[key]; !exists {
214 groups[key] = &armGroup{
215 typeName: key,
216 isDefault: key == "default",
217 }
218 order = append(order, key)
219 }
220 groups[key].arms = append(groups[key].arms, arm)
221 }
222
223 // Generate case for each group
224 for _, key := range order {
225 group := groups[key]
226 g.generateGroupedCase(group, typeSwitch)
227 }
228}
229
230// getPatternCaseKey returns the case key for a pattern.
231// Constructor patterns return their full type name.

Callers 1

generateMatchSwitchMethod · 0.95

Calls 2

getPatternCaseKeyMethod · 0.95
generateGroupedCaseMethod · 0.95

Tested by

no test coverage detected