Skip to content

Commit 617e057

Browse files
committed
[Sema] Avoid merging type variables that can have different results in CS.
This patch avoids merging type variables inside UnresolvedMemberExpr and those outside, because they may not always be equivalent in CS. Resolves: SR-8385.
1 parent 175db41 commit 617e057

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/Sema/CSGen.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ namespace {
317317
return { false, expr };
318318
}
319319

320+
// Don't walk into unresolved member expressions - we avoid merging type
321+
// variables inside UnresolvedMemberExpr and those outside, since they
322+
// should be allowed to behave independently in CS.
323+
if (isa<UnresolvedMemberExpr>(expr)) {
324+
return {false, expr };
325+
}
326+
320327
return { true, expr };
321328
}
322329

test/Constraints/array_literal.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,19 @@ func testConditional(i: Int, s: String) {
340340
let _: PArray<Int> = [i, i, i]
341341
let _: PArray<String> = [s, s, s] // expected-error{{cannot convert value of type '[String]' to specified type 'PArray<String>'}}
342342
}
343+
344+
345+
// SR-8385
346+
enum SR8385: ExpressibleByStringLiteral {
347+
case text(String)
348+
init(stringLiteral value: String) {
349+
self = .text(value)
350+
}
351+
}
352+
353+
func testSR8385() {
354+
let _: [SR8385] = [SR8385("hello")]
355+
let _: [SR8385] = [.text("hello")]
356+
let _: [SR8385] = ["hello", SR8385.text("world")]
357+
let _: [SR8385] = ["hello", .text("world")]
358+
}

0 commit comments

Comments
 (0)