# Tests that inner structs within a definition template constraint are not
# incorrectly treated as closed when unified via a non-definition value.
# https://cuelang.org/issue/359
-- in.cue --
#simple: {
	peso: *1 | int
	edad: *2 | int
}

// Second struct is not considered closed, as expected
good: #simple & {
	peso: 4
}

#complex: {
	things: [string]: #simple
}

// Still, no closedness issue in the second struct
#many: #complex & {
	things: hola: peso: 2
	things: sol: peso:  3
}

// Inner struct in second struct IS considered closed: why?
bad: #many & {
	things: hola: peso: 2
}

// non-definition equivalent
many: #complex & {
	things: hola: peso: 2
	things: sol: peso:  3
}

// Now inner struct on second struct is NOT considered closed
notbad: many & {
	things: hola: peso: 2
}
-- out/compile --
--- in.cue
{
  #simple: {
    peso: (*1|int)
    edad: (*2|int)
  }
  good: (〈0;#simple〉 & {
    peso: 4
  })
  #complex: {
    things: {
      [string]: 〈2;#simple〉
    }
  }
  #many: (〈0;#complex〉 & {
    things: {
      hola: {
        peso: 2
      }
    }
    things: {
      sol: {
        peso: 3
      }
    }
  })
  bad: (〈0;#many〉 & {
    things: {
      hola: {
        peso: 2
      }
    }
  })
  many: (〈0;#complex〉 & {
    things: {
      hola: {
        peso: 2
      }
    }
    things: {
      sol: {
        peso: 3
      }
    }
  })
  notbad: (〈0;many〉 & {
    things: {
      hola: {
        peso: 2
      }
    }
  })
}
