PHondogo
10/16/2026, 1:04 PMconstraint<String> NotEmpty {
fun validate(v: String) {
if (v.isEmpty()) {
throw ConstraintValidationException("Empty string")
}
}
}
constraint<String> NoSpace {
fun validate(v: String) {
if (v.contains(' ') {
throw ConstraintValidationException("Spaces in string")
}
}
}
typealias SeveralConstraints = NotEmpty | NoSpace
fun test(str: @NotEmpty String) {
....
}
fun test2(str: @SeveralConstraints String) {
test(str) // no generated code fo validation because str already validated for NotEmpty that is included in SeveralConstraints
}
fun test3(str: @NotEmpty String) {
test(str) // no generated code fo validation because str already validated
test2(str) // compiler generates code for validation NoSpace, NotEmpty is already validated
}Youssef Shoaib [MOD]
10/16/2026, 1:16 PMfun test3(str: @NotEmpty String) {
test(str) // no generated code fo validation because str already validated
test2(str as (@SeveralConstraints String)) // compiler generates code for validation NoSpace, NotEmpty is already validated
}PHondogo
10/16/2026, 1:16 PMStarr
10/16/2026, 2:06 PMYoussef Shoaib [MOD]
10/16/2026, 2:08 PMis and as would be nice! I.e. is checking the underlying condition, and as throwing an error if the condition doesn't match