-- in.cue --
// Given the existence of this field, embedDefault is a struct. This
// means that embedding this conjunction into `embedDefault` itself should
// make it resolve to `{a: 2}`.

default: {
	y: *1 | {a: 2}
	y
}

unambiguous: {
	y: 1 | {a: 2}
	y
}

forDefault: {
	y: *1 | {a: 2}
	for x in [1] {y}
}

// Carry over default to first disjunct.
openDefault: {
	#y: *1 | {a: 2}
	#y
}

openAmbiguous: {
	#y: 1 | {a: 2}
	#y
}

forceStruct: {
	#y: 1 | {a: 2}
	#y
	{}
}

defaultsMulti: {
	a: {
		#def: {
			*{} | {a: string} | {b: string}
			*{} | {c: string} | {d: string}
		}

		a: #def & {a: "foo"}
	}

	b: {
		#def: {
			*{} | {a: string} | {b: string}
			*{} | {c: string} | {d: string}
			*{} | {d: string} | {e: string}
		}

		a: #def & {a: "foo", e: "bar"}
	}
}

nested: {
	a: 1 | 2 | *(
		(3 | 4 | *( 5 | 6 | *7)) & ( 3 | 4 | ( *7 | 8 )))
}
-- issue3415.cue --
// evalv3: calculated embedded scalars with a default value disagree with v2
// when co-located with a hidden field; embedded scalar addition should work.
// https://cuelang.org/issue/3415
issue3415: full: {
	A: #A & {
		i: {
			_a + _b
			_a: 1
			_b: 10
		}
	}
	#A: {
		i: *0 | number
	}
}
issue3415: reduced: {
	a: {
		1 + #b
		#b: 10
	}
	a: *0 | number
}
-- out/compile --
--- in.cue
{
  default: {
    y: (*1|{
      a: 2
    })
    〈0;y〉
  }
  unambiguous: {
    y: (1|{
      a: 2
    })
    〈0;y〉
  }
  forDefault: {
    y: (*1|{
      a: 2
    })
    for _, x in [
      1,
    ] {
      〈2;y〉
    }
  }
  openDefault: {
    #y: (*1|{
      a: 2
    })
    〈0;#y〉
  }
  openAmbiguous: {
    #y: (1|{
      a: 2
    })
    〈0;#y〉
  }
  forceStruct: {
    #y: (1|{
      a: 2
    })
    〈0;#y〉
    {}
  }
  defaultsMulti: {
    a: {
      #def: {
        (*{}|{
          a: string
        }|{
          b: string
        })
        (*{}|{
          c: string
        }|{
          d: string
        })
      }
      a: (〈0;#def〉 & {
        a: "foo"
      })
    }
    b: {
      #def: {
        (*{}|{
          a: string
        }|{
          b: string
        })
        (*{}|{
          c: string
        }|{
          d: string
        })
        (*{}|{
          d: string
        }|{
          e: string
        })
      }
      a: (〈0;#def〉 & {
        a: "foo"
        e: "bar"
      })
    }
  }
  nested: {
    a: (1|2|*((3|4|*(5|6|*7)) & (3|4|(*7|8))))
  }
}
--- issue3415.cue
{
  issue3415: {
    full: {
      A: (〈0;#A〉 & {
        i: {
          (〈0;_a〉 + 〈0;_b〉)
          _a: 1
          _b: 10
        }
      })
      #A: {
        i: (*0|number)
      }
    }
  }
  issue3415: {
    reduced: {
      a: {
        (1 + 〈0;#b〉)
        #b: 10
      }
      a: (*0|number)
    }
  }
}
