Skip to content

Commit 792f8d1

Browse files
committed
[FixedArray] Fix BitwiseCopyable inference.
`FixedArray<T> : BitwiseCopyable` iff `T : BitwiwseCopyable`; determining this requires using `checkConformance`, not `lookupConformance`.
1 parent 4be3990 commit 792f8d1

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/AST/Builtins.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,11 +3385,12 @@ bool BuiltinType::isBitwiseCopyable() const {
33853385
return false;
33863386

33873387
case BuiltinTypeKind::BuiltinFixedArray: {
3388-
// Bitwise-copyability depends on the element type.
3388+
// FixedArray<N, X> : BitwiseCopyable whenever X : BitwiseCopyable
33893389
auto bfa = cast<BuiltinFixedArrayType>(this);
33903390
auto &C = bfa->getASTContext();
3391-
return (bool)lookupConformance(bfa->getElementType(),
3392-
C.getProtocol(KnownProtocolKind::BitwiseCopyable));
3391+
return (bool)checkConformance(
3392+
bfa->getElementType(),
3393+
C.getProtocol(KnownProtocolKind::BitwiseCopyable));
33933394
}
33943395
}
33953396
}

test/Sema/bitwise_copyable.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// RUN: %target-typecheck-verify-swift \
2+
// RUN: -disable-experimental-parser-round-trip \
23
// RUN: -disable-availability-checking \
34
// RUN: -enable-experimental-feature NonescapableTypes \
5+
// RUN: -enable-experimental-feature ValueGenerics \
46
// RUN: -enable-experimental-feature Sensitive \
57
// RUN: -enable-builtin-module \
68
// RUN: -debug-diagnostic-names
79

10+
// FIXME: Remove -disable-experimental-parser-round-trip when it's not required for using ValueGenerics.
11+
812
// REQUIRES: swift_feature_NonescapableTypes
13+
// REQUIRES: swift_feature_ValueGenerics
914
// REQUIRES: swift_feature_Sensitive
1015

1116
//==============================================================================
@@ -109,6 +114,17 @@ func passS_Implicit_Sensitive(_ s: S_Implicit_Sensitive) {
109114
// expected-note@-94 {{where_requirement_failure_one_subst}}
110115
}
111116

117+
import Builtin
118+
119+
func passFixedArray1N<T>(_ fa: Builtin.FixedArray<1, T>) {
120+
take1(fa) // expected-error {{type_does_not_conform_decl_owner}}
121+
// expected-note@-101 {{where_requirement_failure_one_subst}}
122+
}
123+
124+
func passFixedArray1N<T : BitwiseCopyable>(_ fa: Builtin.FixedArray<1, T>) {
125+
take1(fa)
126+
}
127+
112128
//==============================================================================
113129
//===========================DEPENDENCY-FREE TESTS=(END)======================}}
114130
//==============================================================================

0 commit comments

Comments
 (0)