Skip to content

Commit fc819d7

Browse files
committed
Make @abi type comparison ignore tuple labels
1 parent 578240d commit fc819d7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -9425,6 +9425,22 @@ class ABIDeclChecker : public ASTComparisonVisitor<ABIDeclChecker> {
94259425
if (!normConstraint->isExistentialType())
94269426
return normConstraint;
94279427
}
9428+
9429+
// Tuples: Remove labels.
9430+
if (auto tuple = original->getAs<TupleType>()) {
9431+
bool needsNormalization = false;
9432+
SmallVector<TupleTypeElt, 8> unlabeledElements;
9433+
9434+
for (auto elem : tuple->getElements()) {
9435+
needsNormalization |= !elem.getName().empty();
9436+
unlabeledElements.push_back(elem.getWithoutName());
9437+
}
9438+
9439+
if (!needsNormalization)
9440+
return tuple;
9441+
9442+
return TupleType::get(unlabeledElements, tuple->getASTContext());
9443+
}
94289444

94299445
// TODO: Allow Optional/non-Optional variance when ABI-compatible?
94309446
// TODO: Allow variance in exact class of object?

test/attr/attr_abi.swift

+9
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ func intForFloatParam(_: Int) -> Int { fatalError() } // expected-note @:26 {{sh
378378
@abi(func floatForIntResult(_: Int) -> Float) // expected-error @:40 {{type 'Float' in '@abi' should match 'Int'}}
379379
func intForFloatResult(_: Int) -> Int { fatalError() } // expected-note @:35 {{should match type here}}
380380

381+
@abi(func labeledForUnlabeledTuple(_: (x: Int, y: Int)))
382+
func labeledForUnlabeledTuple(_: (Int, Int)) {}
383+
384+
@abi(func unlabeledForLabeledTuple(_: (Int, Int)))
385+
func unlabeledForLabeledTuple(_: (x: Int, y: Int)) {}
386+
387+
@abi(func labeledForLabeledTuple(_: (x: Int, y: Int)))
388+
func labeledForLabeledTuple(_: (a: Int, b: Int)) {}
389+
381390
@abi(
382391
func testDefaultArguments(
383392
a: Int,

0 commit comments

Comments
 (0)