Skip to content

Commit fac5ffe

Browse files
author
Sima Nerush
committed
[Sema] Record a fix about extra parens for computed properties
1 parent a7dbfe4 commit fac5ffe

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7757,14 +7757,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
77577757
if (auto packExpansion = type2->getAs<PackExpansionType>()) {
77587758
auto countType = simplifyType(packExpansion->getCountType(), flags);
77597759
if (auto paramPack = countType->getAs<PackType>()) {
7760-
if (auto *tuple = type1->getAs<TupleType>()) {
7761-
if (tuple->getNumElements() == paramPack->getNumElements()) {
7762-
if (recordFix(
7763-
DestructureTupleToMatchPackExpansionParameter::create(
7764-
*this, paramPack, loc))) {
7765-
return getTypeMatchFailure(loc);
7766-
}
7760+
if (type1->is<TupleType>() && paramPack->getNumElements() >= 1) {
7761+
if (recordFix(DestructureTupleToMatchPackExpansionParameter::create(
7762+
*this, paramPack, loc))) {
7763+
return getTypeMatchFailure(loc);
77677764
}
7765+
return getTypeMatchSuccess();
77687766
}
77697767
}
77707768
}
@@ -13469,14 +13467,16 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1346913467
auto paramPack = type2->castTo<PackType>();
1347013468

1347113469
// Tailed diagnostic to explode tuples.
13470+
// FIXME: This is very similar to
13471+
// 'cannot_convert_single_tuple_into_multiple_arguments'; can we emit
13472+
// both of these in the same place?
1347213473
if (argPack->getNumElements() == 1) {
13473-
if (auto *tuple = argPack->getElementType(0)->getAs<TupleType>()) {
13474-
if (tuple->getNumElements() == paramPack->getNumElements()) {
13475-
return recordShapeFix(
13476-
DestructureTupleToMatchPackExpansionParameter::create(
13477-
*this, paramPack, loc),
13478-
/*impact=*/2 * paramPack->getNumElements());
13479-
}
13474+
if (argPack->getElementType(0)->is<TupleType>() &&
13475+
paramPack->getNumElements() >= 1) {
13476+
return recordShapeFix(
13477+
DestructureTupleToMatchPackExpansionParameter::create(
13478+
*this, paramPack, loc),
13479+
/*impact=*/2 * paramPack->getNumElements());
1348013480
}
1348113481
}
1348213482

test/Constraints/pack-expansion-expressions.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,16 +608,43 @@ func test_that_expansions_are_bound_early() {
608608
// https://github.com/apple/swift/issues/66393
609609
do {
610610
struct S<each T> {
611-
var property: (repeat each T) -> Void { // expected-note {{'property' declared here}}
611+
var property: (repeat each T) -> Void { // expected-note 4 {{'property' declared here}}
612612
get {}
613613
}
614614

615-
func method(_: repeat each T) {} // expected-note {{'method' declared here}}
615+
func method(_: repeat each T) {} // expected-note 4 {{'method' declared here}}
616616
}
617617
S<Int, Bool>().method((5, true))
618618
// expected-error@-1 {{value pack expansion at parameter #0 expects 2 separate arguments; remove extra parentheses to change tuple into separate arguments}}
619619

620+
S<Int, Bool>().method((5, true, 6))
621+
// expected-error@-1 {{value pack expansion at parameter #0 expects 2 separate arguments; remove extra parentheses to change tuple into separate arguments}}
622+
620623
S<Int, Bool>().property((5, true))
621624
// expected-error@-1 {{value pack expansion at parameter #0 expects 2 separate arguments; remove extra parentheses to change tuple into separate arguments}}
622-
// expected-error@-2 {{cannot pass value pack expansion to non-pack parameter of type 'repeat each T'}}
625+
626+
S<Int, Bool>().property((5, true, 6))
627+
// expected-error@-1 {{value pack expansion at parameter #0 expects 2 separate arguments; remove extra parentheses to change tuple into separate arguments}}
628+
629+
func foo<each U>(u: repeat each U) {
630+
S<repeat each U>().property((3, 4, 5))
631+
// expected-error@-1 {{value pack expansion at parameter #0 expects 1 separate arguments; remove extra parentheses to change tuple into separate arguments}}
632+
633+
// FIXME: The count of 'repeat each U' is not statically known, but error suggests that it is 1.
634+
S<repeat each U>().method((3, 4, 5))
635+
// expected-error@-1 {{value pack expansion at parameter #0 expects 1 separate arguments; remove extra parentheses to change tuple into separate arguments}}
636+
// FIXME: Bad diagnostics
637+
// expected-error@-3 {{pack expansion requires that 'each U' and '_' have the same shape}}
638+
// expected-error@-4 {{pack expansion requires that 'each U' and '_.RawValue' have the same shape}}
639+
640+
// FIXME: The count of '(Int, Int), repeat each U' is not statically known, but error suggests that it is 2.
641+
S<(Int, Int), repeat each U>().method((3, 4))
642+
// expected-error@-1 {{value pack expansion at parameter #0 expects 2 separate arguments; remove extra parentheses to change tuple into separate arguments}}
643+
// FIXME: Duplicate diagnostics
644+
// expected-error@-3 2 {{pack expansion requires that 'each U' and '' have the same shape}}
645+
646+
// FIXME: The count of '(Int, Int), repeat each U' is not statically known, but error suggests that it is 2.
647+
S<(Int, Int), repeat each U>().property((3, 4))
648+
// expected-error@-1 {{value pack expansion at parameter #0 expects 2 separate arguments; remove extra parentheses to change tuple into separate arguments}}
649+
}
623650
}

0 commit comments

Comments
 (0)