Skip to content

Commit a102341

Browse files
authored
Merge pull request #11640 from gibachan/fixit-nested-static-value
[Qol]Fixit nested static value
2 parents b929669 + 559ad71 commit a102341

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ diagnoseTypeMemberOnInstanceLookup(Type baseObjTy,
25602560
->getAsNominalTypeOrNominalTypeExtensionContext();
25612561
SmallString<32> typeName;
25622562
llvm::raw_svector_ostream typeNameStream(typeName);
2563-
typeNameStream << nominal->getName() << ".";
2563+
typeNameStream << nominal->getSelfInterfaceType() << ".";
25642564

25652565
Diag->fixItInsert(loc, typeNameStream.str());
25662566
return;

test/Compatibility/dot_keywords.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 3
2+
3+
// Static function in protocol should have `Self.` instead of its protocol name
4+
protocol P {}
5+
6+
extension P {
7+
static func f1() {}
8+
9+
func g() {
10+
f1() // expected-error {{use of unresolved identifier 'f1'}}
11+
}
12+
}
13+

test/expr/postfix/dot/dot_keywords.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -swift-version 4
22

33
let x: Int = 1
44
let y: Int = x.self
@@ -77,3 +77,31 @@ class ClassWithDeinitMember {
7777

7878
let instanceWithDeinitMember = ClassWithDeinitMember()
7979
_ = instanceWithDeinitMember.deinit
80+
81+
82+
// SR-5715 : Fix variable name in nested static value
83+
struct SR5715 {
84+
struct A {
85+
struct B {}
86+
}
87+
}
88+
89+
extension SR5715.A.B {
90+
private static let x: Int = 5
91+
92+
func f() -> Int {
93+
return x // expected-error {{static member 'x' cannot be used on instance of type 'SR5715.A.B'}} {{12-12=SR5715.A.B.}}
94+
}
95+
}
96+
97+
// Static function in protocol should have `Self.` instead of its protocol name
98+
protocol P {}
99+
100+
extension P {
101+
static func f() {}
102+
103+
func g() {
104+
f() // expected-error {{static member 'f' cannot be used on instance of type 'Self'}} {{5-5=Self.}}
105+
}
106+
}
107+

0 commit comments

Comments
 (0)