@@ -2479,10 +2479,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2479
2479
}
2480
2480
}
2481
2481
2482
- // If this is an init accessor property with a default initializer,
2483
- // make sure that it subsumes initializers of all of its "initializes"
2484
- // stored properties.
2485
2482
if (auto *var = PBD->getSingleVar ()) {
2483
+
2484
+ // If this is an init accessor property with a default initializer,
2485
+ // make sure that it subsumes initializers of all of its "initializes"
2486
+ // stored properties.
2486
2487
auto *initAccessor = var->getAccessor (AccessorKind::Init);
2487
2488
if (initAccessor && PBD->isInitialized (0 )) {
2488
2489
for (auto *property : initAccessor->getInitializedProperties ()) {
@@ -2491,6 +2492,26 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2491
2492
propertyBinding->setInitializerSubsumed (0 );
2492
2493
}
2493
2494
}
2495
+
2496
+ // If we have a pure noncopyable type, we cannot have explicit read/set
2497
+ // accessors since this means that we cannot call mutating methods without
2498
+ // copying. We do not want to support types that one cannot define a
2499
+ // modify operation via a get/set or a modify.
2500
+ if (var->getInterfaceType ()->isPureMoveOnly ()) {
2501
+ if (auto *read = var->getAccessor (AccessorKind::Read)) {
2502
+ if (!read->isImplicit ()) {
2503
+ if (auto *set = var->getAccessor (AccessorKind::Set)) {
2504
+ if (!set->isImplicit ()) {
2505
+ var->diagnose (diag::noncopyable_cannot_have_read_set_accessor,
2506
+ 0 );
2507
+ PBD->setInvalid ();
2508
+ var->setInvalid ();
2509
+ return ;
2510
+ }
2511
+ }
2512
+ }
2513
+ }
2514
+ }
2494
2515
}
2495
2516
}
2496
2517
@@ -2562,6 +2583,23 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2562
2583
.fixItReplace (SD->getStaticLoc (), " static" );
2563
2584
}
2564
2585
2586
+ // Reject noncopyable typed subscripts with read/set accessors since we
2587
+ // cannot define modify operations upon them without copying the read.
2588
+ if (SD->getElementInterfaceType ()->isPureMoveOnly ()) {
2589
+ if (auto *read = SD->getAccessor (AccessorKind::Read)) {
2590
+ if (!read->isImplicit ()) {
2591
+ if (auto *set = SD->getAccessor (AccessorKind::Set)) {
2592
+ if (!set->isImplicit ()) {
2593
+ SD->diagnose (diag::noncopyable_cannot_have_read_set_accessor,
2594
+ 1 );
2595
+ SD->setInvalid ();
2596
+ return ;
2597
+ }
2598
+ }
2599
+ }
2600
+ }
2601
+ }
2602
+
2565
2603
// Now check all the accessors.
2566
2604
SD->visitEmittedAccessors ([&](AccessorDecl *accessor) {
2567
2605
visit (accessor);
0 commit comments