11.1. Miscellaneous contract annotations
The CONTRACTS module provides compile-time type constraints for generic function
arguments. Annotations like [expect_any_array], [expect_any_enum],
[expect_any_numeric], and [expect_any_struct] restrict which types
can instantiate a generic parameter, producing clear error messages on mismatch.
See Contracts for a hands-on tutorial.
All functions and symbols are in “contracts” module, use require to get access to it.
require daslib/contracts
Example:
require daslib/contracts
[!expect_dim(a)]
def process(a) {
return "scalar"
}
[expect_dim(a)]
def process(a) {
return "array"
}
[export]
def main() {
var arr : int[3]
print("{process(42)}\n")
print("{process(arr)}\n")
}
// output:
// scalar
// array
11.1.1. Function annotations
- expect_any_variant
Function annotation expect_any_variant
- expect_any_workhorse
Function annotation expect_any_workhorse
- expect_any_function
Function annotation expect_any_function
- expect_any_lambda
Function annotation expect_any_lambda
- expect_ref
Function annotation expect_ref
- expect_any_bitfield
Function annotation expect_any_bitfield
- expect_value_handle
Function annotation expect_value_handle
- expect_any_struct
Function annotation expect_any_struct
- expect_any_enum
Function annotation expect_any_enum
- expect_any_tuple
Function annotation expect_any_tuple
- expect_any_numeric
Function annotation expect_any_numeric
- expect_any_array
Function annotation expect_any_array
- expect_any_vector_type
Function annotation expect_any_vector_type
- expect_pointer
Function annotation expect_pointer
- expect_class
Function annotation expect_class
- expect_any_workhorse_raw
Function annotation expect_any_workhorse_raw
11.1.2. Type queries
- isYetAnotherVectorTemplate(td: TypeDeclPtr ): bool
def isYetAnotherVectorTemplate (td: TypeDeclPtr) : bool
- Arguments:
td : TypeDeclPtr