Skip to content

Commit 9156ecb

Browse files
authored
Merge pull request #18285 from dingobye/sr8385
[Sema] Avoid merging type variables that can have different results in CS.
2 parents 834ad9e + 617e057 commit 9156ecb

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
@@ -318,6 +318,13 @@ namespace {
318318
return { false, expr };
319319
}
320320

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

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)