Skip to content

Commit bb9ab0d

Browse files
authored
Merge pull request #84957 from hamishknight/quick-fix
[Sema] Quick fix for non-copyable type resolution crash
2 parents 24d03a1 + e0e7118 commit bb9ab0d

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3982,8 +3982,9 @@ TypeResolver::resolveASTFunctionTypeParams(TupleTypeRepr *inputRepr,
39823982
}
39833983

39843984
// Validate the presence of ownership for a noncopyable parameter.
3985+
// FIXME: This won't diagnose if the type contains unbound generics.
39853986
if (inStage(TypeResolutionStage::Interface)
3986-
&& !ty->hasUnboundGenericType()) {
3987+
&& !ty->hasUnboundGenericType() && !ty->hasTypeVariable()) {
39873988
diagnoseMissingOwnership(ownership, eltTypeRepr, ty, resolution);
39883989

39893990
// @_staticExclusiveOnly types cannot be passed as 'inout' in function
@@ -5804,6 +5805,7 @@ NeverNullType TypeResolver::resolveVarargType(VarargTypeRepr *repr,
58045805
}
58055806

58065807
// do not allow move-only types as the element of a vararg
5808+
// FIXME: This does not correctly handle type variables and unbound generics.
58075809
if (inStage(TypeResolutionStage::Interface)) {
58085810
auto contextTy = GenericEnvironment::mapTypeIntoContext(
58095811
resolution.getGenericSignature().getGenericEnvironment(), element);
@@ -5990,6 +5992,7 @@ NeverNullType TypeResolver::resolveTupleType(TupleTypeRepr *repr,
59905992
// Track the presence of a noncopyable field for diagnostic purposes only.
59915993
// We don't need to re-diagnose if a tuple contains another tuple, though,
59925994
// since we should've diagnosed the inner tuple already.
5995+
// FIXME: This won't diagnose if the type contains unbound generics
59935996
if (!ctx.LangOpts.hasFeature(Feature::MoveOnlyTuples) &&
59945997
!options.contains(TypeResolutionFlags::SILMode) &&
59955998
inStage(TypeResolutionStage::Interface) &&

test/Sema/editor_placeholders.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ func test_ambiguity_with_placeholders(pairs: [(rank: Int, count: Int)]) -> Bool
4646

4747
let unboundInPlaceholder1: Array<Never> = <#T##Array#> // expected-error{{editor placeholder in source file}}
4848
let unboundInPlaceholder2: Array<Never> = foo(<#T##t: Array##Array<Never>#>) // expected-error{{editor placeholder in source file}}
49+
50+
// Make sure this doesn't crash:
51+
<#T##(Result) -> Void#> // expected-error {{editor placeholder in source file}}
52+
// expected-error@-1 {{generic parameter 'Success' could not be inferred}}
53+
// expected-error@-2 {{generic parameter 'Failure' could not be inferred}}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","signature":"checkRequirementsImpl(llvm::ArrayRef<swift::Requirement>, bool)","signatureAssert":"Assertion failed: (!firstType->hasTypeVariable()), function checkRequirementsImpl"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
struct a<b: ~Copyable
44
extension a: Copyable where b: Copyable
55
let c (a -> d
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","signature":"checkRequirementsImpl(llvm::ArrayRef<swift::Requirement>, bool)","signatureAssert":"Assertion failed: (!firstType->hasTypeVariable()), function checkRequirementsImpl"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
struct a<b: ~Copyable
44
extension a: Copyable where b: Copyable
55
let c = <#T##(a -> d)#>

0 commit comments

Comments
 (0)