Skip to content

Commit c2fa674

Browse files
committed
Add MemberImportVisibility tests for inherited members of classes.
Create some test cases that demonstrate MemberImportVisibility behavior with respect referencing inherited members. There are already tests that demonstrate overrides, but nothing seemed to show the behavior when referencing an inherted member through a derived type. I wanted to verify this behavior so I wrote a test to demonstrate it. It seems reasonable to check-in the test to ensure the behavior remains consistent.
1 parent 6a5ae8d commit c2fa674

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

test/NameLookup/Inputs/MemberImportVisibility/members_A.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum EnumInA {
3535
}
3636

3737
open class BaseClassInA {
38+
public init() {}
3839
open func methodInA() {}
3940
}
4041

test/NameLookup/members_transitive.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: %target-swift-frontend -typecheck %s -I %t -verify -swift-version 5 -package-name TestPackage -enable-experimental-feature MemberImportVisibility -verify-additional-prefix member-visibility-
88

99
import members_C
10-
// expected-member-visibility-note 15{{add import of module 'members_B'}}{{1-1=internal import members_B\n}}
10+
// expected-member-visibility-note 16{{add import of module 'members_B'}}{{1-1=internal import members_B\n}}
1111

1212

1313
func testExtensionMembers(x: X, y: Y<Z>) {
@@ -93,3 +93,9 @@ class DerivedFromClassInC: DerivedClassInC {
9393
}
9494

9595
struct ConformsToProtocolInA: ProtocolInA {} // expected-member-visibility-error{{type 'ConformsToProtocolInA' does not conform to protocol 'ProtocolInA'}} expected-member-visibility-note {{add stubs for conformance}}
96+
97+
func testDerivedMethodAccess() {
98+
DerivedClassInC().methodInC()
99+
DerivedClassInC().methodInB() // expected-member-visibility-error{{instance method 'methodInB()' is not available due to missing import of defining module 'members_B'}}
100+
DerivedFromClassInC().methodInB()
101+
}

0 commit comments

Comments
 (0)