Files
swift-mirror/test/Parse/pound_assert.swift
Marc Rasi bf18697b4f parsing, typechecking, and SILGen for #assert
`#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`.
2018-11-07 16:34:17 -08:00

20 lines
735 B
Swift

// RUN: %target-typecheck-verify-swift -enable-experimental-static-assert
#assert(true, 123) // expected-error{{expected a string literal}}
#assert(true, "error \(1) message") // expected-error{{'#assert' message cannot be an interpolated string literal}}
#assert true, "error message") // expected-error{{expected '(' in #assert directive}}
#assert(, "error message") // expected-error{{expected a condition expression}}
func unbalanced1() {
#assert(true // expected-error{{expected ')' in #assert directive}}
// expected-note @-1 {{to match this opening '('}}
}
func unbalanced2() {
#assert(true, "hello world" // expected-error{{expected ')' in #assert directive}}
// expected-note @-1 {{to match this opening '('}}
}