Skip to content

Commit f818a5d

Browse files
committed
Add inherited member lookup test case
1 parent 3542af9 commit f818a5d

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
struct Base1 {
4+
int method(void) const { return 1; }
5+
};
6+
7+
struct IBase1 : Base1 { };
8+
9+
struct IIBase1 : IBase1 { };

test/Interop/Cxx/class/inheritance/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ module FunctionsObjC {
4343
requires cplusplus
4444
requires objc
4545
}
46+
47+
module InheritedLookup {
48+
header "inherited-lookup.h"
49+
requires cplusplus
50+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -cxx-interoperability-mode=default)
2+
//
3+
// REQUIRES: executable_test
4+
import InheritedLookup
5+
import StdlibUnittest
6+
7+
var InheritedMemberTestSuite = TestSuite("Test if inherited lookup works")
8+
9+
InheritedMemberTestSuite.test("IIBase1::method() resolves to grandparent") {
10+
let iibase1 = IIBase1()
11+
expectEqual(iibase1.method(), 1)
12+
}
13+
14+
runAllTests()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %S/Inputs -cxx-interoperability-mode=default
2+
import InheritedLookup
3+
4+
extension IIBase1 {
5+
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+
method()
14+
}
15+
}
16+
17+
func f(v: IIBase1) {
18+
v.missing() // expected-error {{'IIBase1' has no member 'missing'}}
19+
v.method()
20+
}

0 commit comments

Comments
 (0)