Skip to content

Commit 7558832

Browse files
authored
Merge pull request #37734 from xedin/rdar-78425221
[CSBindings] Don't record variable adjacency for `member chain base` constraint
2 parents 106357b + b881142 commit 7558832

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,6 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
12141214
if (!bindingTypeVar)
12151215
return None;
12161216

1217-
AdjacentVars.insert({bindingTypeVar, constraint});
1218-
12191217
// If current type variable is associated with a code completion token
12201218
// it's possible that it doesn't have enough contextual information
12211219
// to be resolved to anything, so let's note that fact in the potential
@@ -1237,14 +1235,24 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
12371235
assert(kind == AllowedBindingKind::Supertypes);
12381236
SupertypeOf.insert({bindingTypeVar, constraint});
12391237
}
1238+
1239+
AdjacentVars.insert({bindingTypeVar, constraint});
12401240
break;
12411241
}
12421242

12431243
case ConstraintKind::Bind:
12441244
case ConstraintKind::BindParam:
1245-
case ConstraintKind::Equal:
1245+
case ConstraintKind::Equal: {
1246+
EquivalentTo.insert({bindingTypeVar, constraint});
1247+
AdjacentVars.insert({bindingTypeVar, constraint});
1248+
break;
1249+
}
1250+
12461251
case ConstraintKind::UnresolvedMemberChainBase: {
12471252
EquivalentTo.insert({bindingTypeVar, constraint});
1253+
1254+
// Don't record adjacency between base and result types,
1255+
// this is just an auxiliary contraint to enforce ordering.
12481256
break;
12491257
}
12501258

test/Constraints/static_members_on_protocol_in_generic_context.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,30 @@ func test_no_warning_about_optional_base() {
316316

317317
test(.warnTest) // Ok and no warning even though the `warnTest` name is shadowed
318318
}
319+
320+
// rdar://78425221 - invalid defaulting of literal argument when base is inferred from protocol
321+
322+
protocol Style {}
323+
324+
struct FormatString : ExpressibleByStringInterpolation {
325+
init(stringLiteral: String) {}
326+
}
327+
328+
struct Number : ExpressibleByIntegerLiteral {
329+
init(integerLiteral: Int) {}
330+
}
331+
332+
struct TestStyle: Style {
333+
public init(format: FormatString) {
334+
}
335+
}
336+
337+
extension Style where Self == TestStyle {
338+
static func formattedString(format: FormatString) -> TestStyle { fatalError() }
339+
static func number(_: Number) -> TestStyle { fatalError() }
340+
}
341+
342+
func acceptStyle<S: Style>(_: S) {}
343+
344+
acceptStyle(.formattedString(format: "hi")) // Ok
345+
acceptStyle(.number(42)) // Ok

0 commit comments

Comments
 (0)