Skip to content

Commit 3244bff

Browse files
committed
[CS] Handle TVO_CanBindToPack in mergeEquivalenceClasses
Previously we could incorrectly propagate `TVO_CanBindToPack` to a type variable that cannot bound to a pack type.
1 parent 439afd6 commit 3244bff

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,12 @@ class TypeVariableType::Implementation {
582582
recordBinding(*trail);
583583
getTypeVariable()->Bits.TypeVariableType.Options &= ~TVO_CanBindToNoEscape;
584584
}
585+
586+
if (canBindToPack() && !otherRep->getImpl().canBindToPack()) {
587+
if (trail)
588+
recordBinding(*trail);
589+
getTypeVariable()->Bits.TypeVariableType.Options &= ~TVO_CanBindToPack;
590+
}
585591
}
586592

587593
/// Retrieve the fixed type that corresponds to this type variable,

test/Constraints/pack-expansion-expressions.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,15 @@ func testInvalidDecomposition() {
803803
func id<T>(_ x: T) -> T {}
804804
let (a, b) = id((repeat each undefined)) // expected-error {{cannot find 'undefined' in scope}}
805805
}
806+
807+
func testPackToScalarShortFormConstructor() {
808+
struct S {
809+
init(_ x: Int) {}
810+
init<T>(_ x: T) {}
811+
}
812+
813+
// Make sure we diagnose.
814+
func foo<each T>(_ xs: repeat each T) {
815+
S(repeat each xs) // expected-error {{cannot pass value pack expansion to non-pack parameter of type 'Int'}}
816+
}
817+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"std::__1::optional<swift::Type> llvm::function_ref<std::__1::optional<swift::Type> (swift::TypeBase*)>::callback_fn<swift::constraints::FailureDiagnostic::resolveType(swift::Type, bool, bool) const::$_0>(long, swift::TypeBase*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
Array(repeat a
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// {"kind":"emit-silgen","original":"6943e75f","signature":"swift::SILFunctionType::SILFunctionType(swift::GenericSignature, swift::SILExtInfo, swift::SILCoroutineKind, swift::ParameterConvention, llvm::ArrayRef<swift::SILParameterInfo>, llvm::ArrayRef<swift::SILYieldInfo>, llvm::ArrayRef<swift::SILResultInfo>, std::__1::optional<swift::SILResultInfo>, swift::SubstitutionMap, swift::SubstitutionMap, swift::ASTContext const&, swift::RecursiveTypeProperties, swift::ProtocolConformanceRef)"}
2+
// RUN: not %target-swift-frontend -emit-silgen %s
3+
func a<each b : BinaryInteger>(c : repeat each b) {
4+
UInt32(repeat each c)
5+
}

0 commit comments

Comments
 (0)