Skip to content

Commit 21b47fb

Browse files
authored
Merge pull request #24814 from DougGregor/property-delegate-bad-init-assertion
2 parents 6caedcd + 90859ad commit 21b47fb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2590,7 +2590,8 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
25902590

25912591
/// Retrieve the type to which the pattern should be coerced.
25922592
Type getPatternInitType() const {
2593-
if (!appliedPropertyDelegate || initType->hasError())
2593+
if (!appliedPropertyDelegate || initType->hasError() ||
2594+
initType->is<TypeVariableType>())
25942595
return initType;
25952596

25962597
// We applied a property delegate, so dig the pattern initialization

test/decl/var/property_delegates.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,3 +690,22 @@ struct UsesExplicitClosures {
690690
@WrapperAcceptingAutoclosure(body: { return 42 })
691691
var y: Int
692692
}
693+
694+
// ---------------------------------------------------------------------------
695+
// Miscellaneous bugs
696+
// ---------------------------------------------------------------------------
697+
698+
// rdar://problem/50822051 - compiler assertion / hang
699+
@_propertyDelegate
700+
struct PD<Value> {
701+
var value: Value
702+
703+
init<A>(initialValue: Value, a: A) { // expected-note{{'init(initialValue:a:)' declared here}}
704+
self.value = initialValue
705+
}
706+
}
707+
708+
struct TestPD {
709+
@PD(a: "foo") var foo: Int = 42 // expected-error{{property 'foo' with attached delegate cannot initialize both the delegate type and the property}}
710+
// expected-error@-1{{missing argument for parameter 'initialValue' in call}}
711+
}

0 commit comments

Comments
 (0)