[ASTGen] Handle 'read' and 'modify' accessors

This commit is contained in:
Rintaro Ishizaki
2025-03-15 15:49:31 -07:00
parent 7add493002
commit 54da89e4a7
2 changed files with 14 additions and 1 deletions

View File

@@ -393,6 +393,12 @@ extension ASTGenVisitor {
return .modify
case .`init`:
return .`init`
case .read:
precondition(ctx.langOptsHasFeature(.CoroutineAccessors), "(compiler bug) 'read' accessor should only be parsed with 'CoroutineAccessors' feature")
return .read2
case .modify:
precondition(ctx.langOptsHasFeature(.CoroutineAccessors), "(compiler bug) 'modify' accessor should only be parsed with 'CoroutineAccessors' feature")
return .modify2
default:
self.diagnose(.unknownAccessorSpecifier(specifier))
return nil

View File

@@ -1,17 +1,20 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-concurrency -enable-experimental-feature ParserASTGen \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: | %sanitize-address > %t/astgen.ast
// RUN: %target-swift-frontend-dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-concurrency \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: | %sanitize-address > %t/cpp-parser.ast
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-concurrency -enable-experimental-feature ParserASTGen)
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-concurrency -enable-experimental-feature CoroutineAccessors -enable-experimental-feature ParserASTGen)
// REQUIRES: executable_test
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_CoroutineAccessors
// rdar://116686158
// UNSUPPORTED: asan
@@ -108,6 +111,10 @@ func testVars() {
var s: Int {
get async throws { return 0 }
}
var t: Int {
read { yield q }
modify { yield &q }
}
}
func rethrowingFn(fn: () throws -> Void) rethrows {}