Skip to content

Commit fdcb9f8

Browse files
authored
Merge pull request swiftlang#35089 from xedin/rdar-71383770
[ConstraintSystem] Strengthen dependent member type checks while infe…
2 parents 3ebd9be + c6bdeea commit fdcb9f8

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,9 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
865865

866866
// If the type we'd be binding to is a dependent member, don't try to
867867
// resolve this type variable yet.
868-
if (type->is<DependentMemberType>()) {
868+
if (type->getWithoutSpecifierType()
869+
->lookThroughAllOptionalTypes()
870+
->is<DependentMemberType>()) {
869871
SmallVector<TypeVariableType *, 4> referencedVars;
870872
type->getTypeVariables(referencedVars);
871873

@@ -1210,15 +1212,19 @@ Optional<Type> ConstraintSystem::checkTypeOfBinding(TypeVariableType *typeVar,
12101212
}
12111213
}
12121214

1213-
// If the type is a type variable itself, don't permit the binding.
1214-
if (type->getRValueType()->is<TypeVariableType>())
1215-
return None;
1215+
{
1216+
auto objType = type->getWithoutSpecifierType();
12161217

1217-
// Don't bind to a dependent member type, even if it's currently
1218-
// wrapped in any number of optionals, because binding producer
1219-
// might unwrap and try to attempt it directly later.
1220-
if (type->lookThroughAllOptionalTypes()->is<DependentMemberType>())
1221-
return None;
1218+
// If the type is a type variable itself, don't permit the binding.
1219+
if (objType->is<TypeVariableType>())
1220+
return None;
1221+
1222+
// Don't bind to a dependent member type, even if it's currently
1223+
// wrapped in any number of optionals, because binding producer
1224+
// might unwrap and try to attempt it directly later.
1225+
if (objType->lookThroughAllOptionalTypes()->is<DependentMemberType>())
1226+
return None;
1227+
}
12221228

12231229
// Okay, allow the binding (with the simplified type).
12241230
return type;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol OptionalType {
4+
associatedtype Wrapped
5+
var wrapped: Wrapped? { get }
6+
}
7+
8+
protocol DefaultsBridge {
9+
associatedtype T
10+
}
11+
12+
protocol DefaultsSerializable {
13+
typealias T = Bridge.T
14+
associatedtype Bridge: DefaultsBridge
15+
}
16+
17+
protocol DefaultsKeyStore {}
18+
19+
struct DefaultsKeys: DefaultsKeyStore {}
20+
struct DefaultsKey<ValueType> {}
21+
22+
@dynamicMemberLookup
23+
struct DefaultsAdapter<KeyStore: DefaultsKeyStore> {
24+
@available(*, unavailable)
25+
subscript(dynamicMember member: String) -> Never {
26+
fatalError()
27+
}
28+
29+
subscript<T: DefaultsSerializable>(keyPath: KeyPath<KeyStore, DefaultsKey<T>>) -> T.T where T.T == T {
30+
get { fatalError() }
31+
set { fatalError() }
32+
}
33+
34+
subscript<T: DefaultsSerializable>(dynamicMember keyPath: KeyPath<KeyStore, DefaultsKey<T>>) -> T.T where T: OptionalType, T.T == T {
35+
get { fatalError() }
36+
set { fatalError() }
37+
}
38+
}
39+
40+
41+
var Defaults = DefaultsAdapter<DefaultsKeys>()
42+
Defaults[\.missingKey] = "" // expected-error {{}}

0 commit comments

Comments
 (0)