[ASTGen] Generate miscellaneous builtin pound

`#error`, `#warning`, and `#assert`.
Also #_hasSymbol statement condition
This commit is contained in:
Rintaro Ishizaki
2025-03-12 13:59:07 -07:00
parent 1a08018985
commit ac80775201
14 changed files with 503 additions and 150 deletions

View File

@@ -58,5 +58,7 @@ func testPoundIf() {
// pass
} else if #unavailable(macOS 80) {
// pass
} else if #_hasSymbol(Int.self) { // expected-warning {{struct 'Int' is not a weakly linked declaration}}
// pass
}
}

View File

@@ -36,3 +36,18 @@ struct S {
struct ExpansionRequirementTest<each T> {}
extension ExpansionRequirementTest where repeat each T == Int {} // expected-error {{same-element requirements are not yet supported}}
#warning("this is a warning") // expected-warning {{this is a warning}}
func testDiagnosticInFunc() {
#error("this is an error") // expected-error {{this is an error}}
}
class TestDiagnosticInNominalTy {
#error("this is an error member") // expected-error {{this is an error member}}
}
#if FLAG_NOT_ENABLED
#error("error in inactive") // no diagnostis
#endif

View File

@@ -0,0 +1,21 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-dump-parse -enable-experimental-feature ParserASTGen \
// RUN: -enable-experimental-feature StaticAssert \
// RUN: | %sanitize-address > %t/astgen.ast
// RUN: %target-swift-frontend-dump-parse \
// RUN: -enable-experimental-feature StaticAssert \
// RUN: | %sanitize-address > %t/cpp-parser.ast
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
// RUN: %target-swift-emit-sil -verify %s -enable-experimental-feature ParserASTGen \
// RUN: -enable-experimental-feature StaticAssert
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_StaticAssert
func testPoundAssert() {
#assert(1 == 1.0, "1 must be 1.0") // OK
#assert(1 == 1.5, "1 is 1.5 ??") // expected-error {{1 is 1.5 ??}}
}