Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add more tests for ExtensionImportVisibility #72969

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/NameLookup/Inputs/Categories/Categories_D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Intentionally empty
1 change: 0 additions & 1 deletion test/NameLookup/Inputs/Categories/Categories_D.swift

This file was deleted.

2 changes: 2 additions & 0 deletions test/NameLookup/Inputs/Categories/Categories_E.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Categories_C
import Categories_D.Submodule
5 changes: 5 additions & 0 deletions test/NameLookup/Inputs/Categories/Submodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import Categories_A;

@interface X (SubmoduleOfD)
- (void)fromSubmoduleOfD;
@end
11 changes: 11 additions & 0 deletions test/NameLookup/Inputs/Categories/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ module Categories_C {
header "Categories_C.h"
export *
}

module Categories_D {
header "Categories_D.h"
export *

explicit module Submodule {
header "Submodule.h"
export *
}
}

8 changes: 8 additions & 0 deletions test/NameLookup/Inputs/extensions_A.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ extension Y: P where T: P { }

public struct Z: P { }

infix operator <<<
infix operator >>>
infix operator <>

extension X {
public func XinA() { }

public static func <<<(a: Self, b: Self) -> Self { a }
}

extension Y {
public func YinA() { }

public static func <<<(a: Self, b: Self) -> Self { a }
}
5 changes: 5 additions & 0 deletions test/NameLookup/Inputs/extensions_B.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import extensions_A


extension X {
public func XinB() { }

public static func >>>(a: Self, b: Self) -> Self { b }
}

extension Y {
public func YinB() { }

public static func >>>(a: Self, b: Self) -> Self { b }
}

6 changes: 5 additions & 1 deletion test/NameLookup/Inputs/extensions_C.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@_exported import extensions_A
import extensions_B


extension X {
public func XinC() { }

public static func <>(a: Self, b: Self) -> Self { a }
}

extension Y {
public func YinC() { }
}

public static func <>(a: Self, b: Self) -> Self { a }
}
9 changes: 9 additions & 0 deletions test/NameLookup/extensions_transitive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@
import extensions_C
// expected-note 2{{add import of module 'extensions_B'}}{{1-1=import extensions_B\n}}
func test(x: X, y: Y<Z>) {
// Declared in extensions_A
x.XinA()
y.YinA()
_ = x <<< x
_ = y <<< y

// Declared in extensions_B
x.XinB() // expected-error{{instance method 'XinB()' is not available due to missing import of defining module 'extensions_B'}}
y.YinB() // expected-error{{instance method 'YinB()' is not available due to missing import of defining module 'extensions_B'}}
_ = x >>> x // expected-error{{cannot find operator '>>>' in scope}}
_ = y >>> y // expected-error{{cannot find operator '>>>' in scope}}

// Declared in extensions_C
x.XinC()
y.YinC()
_ = x <> x
_ = y <> y
}
9 changes: 6 additions & 3 deletions test/NameLookup/extensions_transitive_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
// RUN: %target-swift-frontend -emit-module -I %t -I %S/Inputs/Categories -o %t %S/Inputs/Categories/Categories_A.swift
// RUN: %target-swift-frontend -emit-module -I %t -I %S/Inputs/Categories -o %t %S/Inputs/Categories/Categories_B.swift
// RUN: %target-swift-frontend -emit-module -I %t -I %S/Inputs/Categories -o %t %S/Inputs/Categories/Categories_C.swift
// RUN: %target-swift-frontend -emit-module -I %t -I %S/Inputs/Categories -o %t %S/Inputs/Categories/Categories_D.swift
// RUN: %target-swift-frontend -emit-module -I %t -I %S/Inputs/Categories -o %t %S/Inputs/Categories/Categories_E.swift
// RUN: %target-swift-frontend -typecheck %s -I %t -I %S/Inputs/Categories -verify -enable-experimental-feature ExtensionImportVisibility

// REQUIRES: objc_interop

import Categories_B
import Categories_D
// expected-note 2 {{add import of module 'Categories_C'}}{{1-1=import Categories_C\n}}
import Categories_E

// expected-note@-1 2 {{add import of module 'Categories_C'}}{{1-1=import Categories_C\n}}
// expected-note@-2 {{add import of module 'Categories_D'}}{{1-1=import Categories_D\n}}
func test(x: X) {
x.fromA()
x.fromOverlayForA()
x.fromB()
x.fromOverlayForB()
x.fromC() // expected-error {{class method 'fromC()' is not available due to missing import of defining module 'Categories_C'}}
x.fromOverlayForC() // expected-error {{instance method 'fromOverlayForC()' is not available due to missing import of defining module 'Categories_C'}}
x.fromSubmoduleOfD() // expected-error {{class method 'fromSubmoduleOfD()' is not available due to missing import of defining module 'Categories_D'}}
}

func testAnyObject(a: AnyObject) {
Expand Down