Skip to content

Commit bee4cfe

Browse files
committed
[PreCheckTarget] Consider UnresolvedSpecializeExpr a chain expression
Optional chain and unresolved member chain should consider a generic specialization as a chain expression. rdar://140378864
1 parent 6221b29 commit bee4cfe

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/Sema/PreCheckTarget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ static Expr *getMemberChainSubExpr(Expr *expr) {
333333
return SE->getBase();
334334
} else if (auto *DSE = dyn_cast<DotSelfExpr>(expr)) {
335335
return DSE->getSubExpr();
336+
} else if (auto *USE = dyn_cast<UnresolvedSpecializeExpr>(expr)) {
337+
return USE->getSubExpr();
336338
} else if (auto *CCE = dyn_cast<CodeCompletionExpr>(expr)) {
337339
return CCE->getBase();
338340
} else {

test/Sema/generic_specialization.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix swift6-
33

44
extension Int {
5-
func foo() -> Int {} // expected-note 2 {{'foo()' declared here}}
5+
func foo() -> Int {} // expected-note 3 {{'foo()' declared here}}
66
var bar: Int {
77
get {}
88
}
@@ -40,6 +40,12 @@ func test(i: Int) {
4040
// expected-swift6-error@-2 {{cannot specialize non-generic type 'Int'}}
4141
}
4242

43+
func testOptionalChain(i: Int?) {
44+
let _ = i?.foo<Int>()
45+
// expected-swift5-warning@-1 {{cannot explicitly specialize instance method 'foo()'}}
46+
// expected-swift6-error@-2 {{cannot explicitly specialize instance method 'foo()'}}
47+
}
48+
4349
extension Bool {
4450
func foo<T>() -> T {} // expected-note {{'foo()' declared here}}
4551
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
4+
struct Outer {
5+
struct Inner {
6+
struct Foo<T> {
7+
static func id(_ v: T) -> T { v }
8+
}
9+
}
10+
}
11+
12+
let _: Outer = .Inner.Foo<Outer>.id(.init())
13+

0 commit comments

Comments
 (0)