-- in.cue --
// cycle is a structural cycle
cycle: a: cycle

// reference to outside structural cycle
r1a: cycle | int
r1b: int | cycle

r2a: cycle | 1
r2b: 1 | cycle

r3a: cycle | null
r3b: null | cycle

r4a: cycle | {}
r4b: {} | cycle

r5a: cycle | []
r5b: [] | cycle

// reference to ancestor node
s1a: {
	x: s1a | int
}
s1b: {
	x: int | s1b
}

s2a: {
	x: s2a | 1
}
s2b: {
	x: 1 | s2b
}

s3a: {
	x: s3a | null
}
s3b: {
	x: null | s3b
}

s4a: {
	x: s4a | {}
}
s4b: {
	x: {} | s4b
}

s5a: {
	x: s5a | []
}
s5b: {
	x: [] | s5b
}
-- issue3042.cue --
// Array element validation not being enforced for elements nested inside
// a struct: invalid values passed validation without error.
// https://cuelang.org/issue/3042
issue3042: {
	// Recursively, any field named "name" should begin with "foo".
	// The data value below should then fail.
	#foo: =~"^foo"
	#nesting: string | {name?: #foo, [string]: #nesting} | [...#nesting]

	data: #nesting & {
		secret: {
			infra: [
				{name: "bar1"}
			]
		}
	}
}
-- out/compile --
--- in.cue
{
  cycle: {
    a: 〈1;cycle〉
  }
  r1a: (〈0;cycle〉|int)
  r1b: (int|〈0;cycle〉)
  r2a: (〈0;cycle〉|1)
  r2b: (1|〈0;cycle〉)
  r3a: (〈0;cycle〉|null)
  r3b: (null|〈0;cycle〉)
  r4a: (〈0;cycle〉|{})
  r4b: ({}|〈0;cycle〉)
  r5a: (〈0;cycle〉|[])
  r5b: ([]|〈0;cycle〉)
  s1a: {
    x: (〈1;s1a〉|int)
  }
  s1b: {
    x: (int|〈1;s1b〉)
  }
  s2a: {
    x: (〈1;s2a〉|1)
  }
  s2b: {
    x: (1|〈1;s2b〉)
  }
  s3a: {
    x: (〈1;s3a〉|null)
  }
  s3b: {
    x: (null|〈1;s3b〉)
  }
  s4a: {
    x: (〈1;s4a〉|{})
  }
  s4b: {
    x: ({}|〈1;s4b〉)
  }
  s5a: {
    x: (〈1;s5a〉|[])
  }
  s5b: {
    x: ([]|〈1;s5b〉)
  }
}
--- issue3042.cue
{
  issue3042: {
    #foo: =~"^foo"
    #nesting: (string|{
      name?: 〈1;#foo〉
      [string]: 〈1;#nesting〉
    }|[
      ...〈1;#nesting〉,
    ])
    data: (〈0;#nesting〉 & {
      secret: {
        infra: [
          {
            name: "bar1"
          },
        ]
      }
    })
  }
}
