Skip to content

Commit d432b8e

Browse files
committed
[Noncopyable] fix subscripts
1 parent bb5fd84 commit d432b8e

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27182718
}
27192719

27202720
void visitSubscriptDecl(SubscriptDecl *SD) {
2721+
auto *DC = SD->getDeclContext();
2722+
27212723
// Force requests that can emit diagnostics.
27222724
(void) SD->getInterfaceType();
27232725
(void) SD->getGenericSignature();
@@ -2768,7 +2770,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27682770
checkDefaultArguments(SD->getIndices());
27692771
checkVariadicParameters(SD->getIndices(), SD);
27702772

2771-
if (SD->getDeclContext()->getSelfClassDecl()) {
2773+
if (DC->getSelfClassDecl()) {
27722774
checkDynamicSelfType(SD, SD->getValueInterfaceType());
27732775

27742776
if (SD->getValueInterfaceType()->hasDynamicSelfType() &&
@@ -2779,15 +2781,15 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27792781

27802782
// Reject "class" methods on actors.
27812783
if (SD->getStaticSpelling() == StaticSpellingKind::KeywordClass &&
2782-
SD->getDeclContext()->getSelfClassDecl() &&
2783-
SD->getDeclContext()->getSelfClassDecl()->isActor()) {
2784+
DC->getSelfClassDecl() &&
2785+
DC->getSelfClassDecl()->isActor()) {
27842786
SD->diagnose(diag::class_subscript_not_in_class, false)
27852787
.fixItReplace(SD->getStaticLoc(), "static");
27862788
}
27872789

27882790
// Reject noncopyable typed subscripts with read/set accessors since we
27892791
// cannot define modify operations upon them without copying the read.
2790-
if (SD->getElementInterfaceType()->isNoncopyable()) {
2792+
if (SD->getElementInterfaceType()->isNoncopyable(DC)) {
27912793
if (auto *read = SD->getAccessor(AccessorKind::Read)) {
27922794
if (!read->isImplicit()) {
27932795
if (auto *set = SD->getAccessor(AccessorKind::Set)) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
// A Swift × Haskell stdlib flavour.
4+
5+
public struct Vector<T: ~Copyable> {
6+
7+
subscript(_ i: UInt) -> T {
8+
fatalError("todo")
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -enable-library-evolution -emit-module -o %t/NoncopyableGenerics.swiftmodule -emit-module-interface-path %t/NoncopyableGenerics.swiftinterface -enable-experimental-feature NoncopyableGenerics %S/Inputs/NoncopyableGenerics.swift
4+
// RUN: %target-swift-frontend -emit-sil -sil-verify-all -I %t %s > /dev/null
5+
6+
7+
import NoncopyableGenerics

0 commit comments

Comments
 (0)