Skip to content

Commit 90859ad

Browse files
committed
[Type checker] Fix assertion/spin with ill-formed property delegate initialization
Fixes rdar://problem/50822051.
1 parent 5aea131 commit 90859ad

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
@@ -2486,7 +2486,8 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
24862486

24872487
/// Retrieve the type to which the pattern should be coerced.
24882488
Type getPatternInitType() const {
2489-
if (!appliedPropertyDelegate || initType->hasError())
2489+
if (!appliedPropertyDelegate || initType->hasError() ||
2490+
initType->is<TypeVariableType>())
24902491
return initType;
24912492

24922493
// 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)