Skip to content

Commit 94a7599

Browse files
committed
Update inherited lookup test to include eager members
1 parent 0f12958 commit 94a7599

File tree

3 files changed

+129
-27
lines changed

3 files changed

+129
-27
lines changed
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#pragma once
22

3-
struct Base1 {
4-
int methodBase(void) const { return 1; }
3+
struct One {
4+
int method(void) const { return 1; }
5+
int operator[](int i) const { return 1; }
56
};
67

7-
struct IBase1 : Base1 {
8-
int methodIBase(void) const { return 11; }
8+
struct IOne : One {
9+
int methodI(void) const { return -1; }
910
};
1011

11-
struct IIBase1 : IBase1 {
12-
int methodIIBase(void) const { return 111; }
12+
struct IIOne : IOne {
13+
int methodII(void) const { return -11; }
14+
};
15+
16+
struct IIIOne : IIOne {
17+
int methodIII(void) const { return -111; }
1318
};

test/Interop/Cxx/class/inheritance/inherited-lookup-executable.swift

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,46 @@ import StdlibUnittest
66

77
var InheritedMemberTestSuite = TestSuite("Test if inherited lookup works")
88

9-
InheritedMemberTestSuite.test("IIBase1::method() resolves to grandparent") {
10-
let iibase1 = IIBase1()
11-
expectEqual(iibase1.methodBase(), 1)
12-
expectEqual(iibase1.methodIBase(), 11)
13-
expectEqual(iibase1.methodIIBase(), 111)
9+
InheritedMemberTestSuite.test("Regular methods resolve to base classes") {
10+
// No inheritance (sanity check)
11+
let one = One()
12+
expectEqual(one.method(), 1)
13+
14+
// One level of inheritance
15+
let iOne = IOne()
16+
expectEqual(iOne.method(), 1)
17+
expectEqual(iOne.methodI(), -1)
18+
19+
// Two levels of inheritance
20+
let iiOne = IIOne()
21+
expectEqual(iiOne.method(), 1)
22+
expectEqual(iiOne.methodI(), -1)
23+
expectEqual(iiOne.methodII(), -11)
24+
25+
// Three levels of inheritance
26+
let iiiOne = IIIOne()
27+
expectEqual(iiiOne.method(), 1)
28+
expectEqual(iiiOne.methodI(), -1)
29+
expectEqual(iiiOne.methodII(), -11)
30+
expectEqual(iiiOne.methodIII(), -111)
31+
}
32+
33+
InheritedMemberTestSuite.test("Eagerly imported methods resolve to base classes") {
34+
// No inheritance (sanity check)
35+
let one = One()
36+
expectEqual(one[0], 1)
37+
38+
// One level of inheritance
39+
let iOne = IOne()
40+
expectEqual(iOne[0], 1)
41+
42+
// Two levels of inheritance
43+
let iiOne = IIOne()
44+
expectEqual(iiOne[0], 1)
45+
46+
// Three levels of inheritance
47+
let iiiOne = IIIOne()
48+
expectEqual(iiiOne[0], 1)
1449
}
1550

1651
runAllTests()
Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,86 @@
11
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %S/Inputs -cxx-interoperability-mode=default
22
import InheritedLookup
33

4-
extension IIBase1 {
4+
extension One {
5+
// Swift extensions of a base class should not affect its derived classes.
6+
// We later attempt to call baseExt() in derived classes, which should fail.
7+
func baseExt() -> Int32 { return 0 }
8+
9+
func ext() {
10+
let _ = baseExt()
11+
let _ = self[0]
12+
let _ = method()
13+
let _ = methodI() // expected-error {{cannot find 'methodI' in scope}}
14+
let _ = methodII() // expected-error {{cannot find 'methodII' in scope}}
15+
let _ = methodIII() // expected-error {{cannot find 'methodIII' in scope}}
16+
}
17+
}
18+
19+
func fOne(v: One) {
20+
let _ = v.baseExt()
21+
let _ = v[0]
22+
let _ = v.method()
23+
let _ = v.methodI() // expected-error {{'One' has no member 'methodI'}}
24+
let _ = v.methodII() // expected-error {{'One' has no member 'methodII'}}
25+
let _ = v.methodIII() // expected-error {{'One' has no member 'methodIII'}}
26+
}
27+
28+
extension IOne {
29+
func ext() {
30+
let _ = baseExt() // expected-error {{cannot find 'baseExt' in scope}}
31+
let _ = self[0]
32+
let _ = method()
33+
let _ = methodI()
34+
let _ = methodII() // expected-error {{cannot find 'methodII' in scope}}
35+
let _ = methodIII() // expected-error {{cannot find 'methodIII' in scope}}
36+
}
37+
}
38+
39+
func fIOne(v: IOne) {
40+
let _ = v.baseExt() // expected-error {{'IOne' has no member 'baseExt'}}
41+
let _ = v[0]
42+
let _ = v.method()
43+
let _ = v.methodI()
44+
let _ = v.methodII() // expected-error {{'IOne' has no member 'methodII'}}
45+
let _ = v.methodIII() // expected-error {{'IOne' has no member 'methodIII'}}
46+
}
47+
48+
extension IIOne {
49+
func ext() {
50+
let _ = baseExt() // expected-error {{cannot find 'baseExt' in scope}}
51+
let _ = self[0]
52+
let _ = method()
53+
let _ = methodI()
54+
let _ = methodII()
55+
let _ = methodIII() // expected-error {{cannot find 'methodIII' in scope}}
56+
}
57+
}
58+
59+
func fIIOne(v: IIOne) {
60+
let _ = v.baseExt() // expected-error {{'IIOne' has no member 'baseExt'}}
61+
let _ = v[0]
62+
let _ = v.method()
63+
let _ = v.methodI()
64+
let _ = v.methodII()
65+
let _ = v.methodIII() // expected-error {{'IIOne' has no member 'methodIII'}}
66+
}
67+
68+
extension IIIOne {
569
func ext() {
6-
// NOTE: we deliberately look up a missing member above because doing so
7-
// forces multiple ClangRecordMemberLookup requests, which should be
8-
// idempotent (though this hasn't always been the case, because bugs).
9-
missing() // expected-error {{cannot find 'missing' in scope}}
10-
11-
// For instance, a non-idempotent ClangRecordMemberLookup would cause
12-
// the following to appear ambiguous:
13-
methodBase()
14-
methodIBase()
15-
methodIIBase()
70+
let _ = baseExt() // expected-error {{cannot find 'baseExt' in scope}}
71+
let _ = self[0]
72+
let _ = method()
73+
let _ = methodI()
74+
let _ = methodII()
75+
let _ = methodIII()
1676
}
1777
}
1878

19-
func f(v: IIBase1) {
20-
v.missing() // expected-error {{'IIBase1' has no member 'missing'}}
21-
v.methodBase()
22-
v.methodIBase()
23-
v.methodIIBase()
79+
func fIIIOne(v: IIIOne) {
80+
let _ = v.baseExt() // expected-error {{'IIIOne' has no member 'baseExt'}}
81+
let _ = v[0]
82+
let _ = v.method()
83+
let _ = v.methodI()
84+
let _ = v.methodII()
85+
let _ = v.methodIII()
2486
}

0 commit comments

Comments
 (0)