@@ -383,8 +383,8 @@ func (n *nodeContext) crossProduct(dst, cross []*nodeContext, dn *envDisjunct, m
383
383
// buffer may grow and has a max size of len(cross) * len(dn.disjuncts).
384
384
tmp := make ([]* nodeContext , 0 , len (cross ))
385
385
386
- leftHasDefault := false
387
- rightHasDefault := false
386
+ leftDropsDefault := true
387
+ rightDropsDefault := true
388
388
389
389
for i , p := range cross {
390
390
ID := n .nextCrossProduct (i , len (cross ), p )
@@ -406,20 +406,21 @@ func (n *nodeContext) crossProduct(dst, cross []*nodeContext, dn *envDisjunct, m
406
406
}
407
407
408
408
tmp = append (tmp , r )
409
- if p .defaultMode == isDefault {
410
- leftHasDefault = true
409
+ if p .defaultMode == isDefault || p . origDefaultMode == isDefault {
410
+ leftDropsDefault = false
411
411
}
412
412
if d .mode == isDefault {
413
- rightHasDefault = true
413
+ rightDropsDefault = false
414
414
}
415
415
}
416
416
}
417
417
418
+ hasNonMaybe := false
418
419
for _ , r := range tmp {
419
420
// Unroll nested disjunctions.
420
421
switch len (r .disjuncts ) {
421
422
case 0 :
422
- r .defaultMode = combineDefault2 (r .defaultMode , r .origDefaultMode , leftHasDefault , rightHasDefault )
423
+ r .defaultMode = combineDefault2 (r .defaultMode , r .origDefaultMode , leftDropsDefault , rightDropsDefault )
423
424
// r did not have a nested disjunction.
424
425
dst = appendDisjunct (n .ctx , dst , r )
425
426
@@ -430,23 +431,34 @@ func (n *nodeContext) crossProduct(dst, cross []*nodeContext, dn *envDisjunct, m
430
431
for _ , x := range r .disjuncts {
431
432
m := combineDefault (r .origDefaultMode , x .defaultMode )
432
433
433
- // TODO(defaults): using rightHasDefault instead of true here is
434
- // not according to the spec, but may result in better user
434
+ // TODO(defaults): using rightHasDefault instead of false here
435
+ // is not according to the spec, but may result in better user
435
436
// ergononmics. See Issue #1304.
436
- x .defaultMode = combineDefault2 (r .defaultMode , m , leftHasDefault , true )
437
+ x .defaultMode = combineDefault2 (r .defaultMode , m , leftDropsDefault , false )
438
+ if x .defaultMode != maybeDefault {
439
+ hasNonMaybe = true
440
+ }
437
441
dst = appendDisjunct (n .ctx , dst , x )
438
442
}
439
443
}
440
444
}
441
445
446
+ if hasNonMaybe {
447
+ for _ , r := range dst {
448
+ if r .defaultMode == maybeDefault {
449
+ r .defaultMode = notDefault
450
+ }
451
+ }
452
+ }
453
+
442
454
return dst
443
455
}
444
456
445
- func combineDefault2 (a , b defaultMode , hasDefaultA , hasDefaultB bool ) defaultMode {
446
- if ! hasDefaultA {
457
+ func combineDefault2 (a , b defaultMode , dropsDefaultA , dropsDefaultB bool ) defaultMode {
458
+ if dropsDefaultA {
447
459
a = maybeDefault
448
460
}
449
- if ! hasDefaultB {
461
+ if dropsDefaultB {
450
462
b = maybeDefault
451
463
}
452
464
return combineDefault (a , b )
0 commit comments