mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
`#assert` is a new static assertion statement that will let us write tests for the new constant evaluation infrastructure that we are working on. `#assert` works by lowering to a `Builtin.poundAssert` SIL instruction. The constant evaluation infrastructure will look for these SIL instructions, const-evaluate their conditions, and emit errors if the conditions are non-constant or false. This commit implements parsing, typechecking and SILGen for `#assert`.
14 lines
327 B
Swift
14 lines
327 B
Swift
// RUN: %target-typecheck-verify-swift -enable-experimental-static-assert
|
|
|
|
#assert(true)
|
|
|
|
#assert(true, "error message")
|
|
|
|
#assert(false)
|
|
|
|
#assert(false, "error message")
|
|
|
|
#assert(123) // expected-error{{'Int' is not convertible to 'Bool'}}
|
|
|
|
#assert(123, "error message") // expected-error{{'Int' is not convertible to 'Bool'}}
|