Skip to content

Commit 70d6257

Browse files
authored
Merge pull request #78893 from slavapestov/fix-issue-77315
Sema: Fix crash in type resolution when tuple type contains type variables
2 parents 18ab461 + f142b30 commit 70d6257

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

lib/AST/Requirement.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,28 +267,24 @@ checkRequirementsImpl(ArrayRef<Requirement> requirements,
267267
while (!worklist.empty()) {
268268
auto req = worklist.pop_back_val();
269269

270-
// Check preconditions.
271-
#ifndef NDEBUG
272-
{
270+
// Check preconditions.
273271
auto firstType = req.getFirstType();
274-
assert((allowTypeParameters || !firstType->hasTypeParameter())
272+
ASSERT((allowTypeParameters || !firstType->hasTypeParameter())
275273
&& "must take a contextual type. if you really are ok with an "
276274
"indefinite answer (and usually YOU ARE NOT), then consider whether "
277275
"you really, definitely are ok with an indefinite answer, and "
278276
"use `checkRequirementsWithoutContext` instead");
279-
assert(!firstType->hasTypeVariable());
277+
ASSERT(!firstType->hasTypeVariable());
280278

281279
if (req.getKind() != RequirementKind::Layout) {
282280
auto secondType = req.getSecondType();
283-
assert((allowTypeParameters || !secondType->hasTypeParameter())
281+
ASSERT((allowTypeParameters || !secondType->hasTypeParameter())
284282
&& "must take a contextual type. if you really are ok with an "
285283
"indefinite answer (and usually YOU ARE NOT), then consider whether "
286284
"you really, definitely are ok with an indefinite answer, and "
287285
"use `checkRequirementsWithoutContext` instead");
288-
assert(!secondType->hasTypeVariable());
286+
ASSERT(!secondType->hasTypeVariable());
289287
}
290-
}
291-
#endif
292288

293289
switch (req.checkRequirement(worklist, /*allowMissing=*/true)) {
294290
case CheckRequirementResult::Success:

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5676,6 +5676,7 @@ NeverNullType TypeResolver::resolveTupleType(TupleTypeRepr *repr,
56765676
inStage(TypeResolutionStage::Interface) &&
56775677
!moveOnlyElementIndex.has_value() &&
56785678
!ty->hasUnboundGenericType() &&
5679+
!ty->hasTypeVariable() &&
56795680
!isa<TupleTypeRepr>(tyR)) {
56805681
auto contextTy = GenericEnvironment::mapTypeIntoContext(
56815682
resolution.getGenericSignature().getGenericEnvironment(), ty);

test/Constraints/issue-77315.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
func foo<T>(_: () -> (Optional<T>, Int)) -> T { fatalError() }
4+
5+
let x: Int = foo { () -> (Optional, Int) in fatalError() }

0 commit comments

Comments
 (0)