Skip to content

Commit f5c596b

Browse files
committed
Test access level check
1 parent 65f1b52 commit f5c596b

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// REQUIRES: swift_swift_parser
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
5+
6+
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) %s -enable-experimental-feature ExpressionMacroDefaultArguments
7+
8+
public typealias Stringified<T> = (T, String)
9+
10+
@freestanding(expression)
11+
public macro publicStringify<T>(_ value: T) -> Stringified<T> = #externalMacro(
12+
module: "MacroDefinition", type: "StringifyMacro"
13+
)
14+
15+
public func publicUsePublic(okay: Stringified<Int> = #publicStringify(0)) {}
16+
func internalUsePublic(okay: Stringified<Int> = #publicStringify(0)) {}
17+
18+
// expected-note@+2{{macro 'stringify' is not '@usableFromInline' or public}}
19+
@freestanding(expression)
20+
macro stringify<T>(_ value: T) -> Stringified<T> = #externalMacro(
21+
module: "MacroDefinition", type: "StringifyMacro"
22+
)
23+
24+
// expected-error@+1{{macro 'stringify' is internal and cannot be referenced from a default argument value}}
25+
public func publicUseInternal(fail: Stringified<Int> = #stringify(0)) {}
26+
func internalUseInternal(okay: Stringified<Int> = #stringify(0)) {}

test/Macros/macro_default_argument_diagnostics.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
public typealias Stringified<T> = (T, String)
99

10-
// expected-note@+2{{macro 'stringify' is not '@usableFromInline' or public}}
1110
@freestanding(expression)
1211
macro stringify<T>(_ value: T) -> Stringified<T> = #externalMacro(
1312
module: "MacroDefinition", type: "StringifyMacro"
@@ -56,8 +55,5 @@ func testIdentifier(notOkay: Stringified<String> = #stringify(myString)) {}
5655
// expected-error@+1{{only literals are permitted}}
5756
func testString(interpolated: Stringified<String> = #stringify("Hello \(0b10001)")) {}
5857

59-
// expected-error@+1{{macro 'stringify' is internal and cannot be referenced from a default argument value}}
60-
public func testAccess(internal: Stringified<Int> = #stringify(0)) {}
61-
6258
// expected-error@+1{{default argument value of type '(Int, String)' cannot be converted to type 'Int'}}
6359
func testReturn(wrongType: Int = #stringify(0)) {}

0 commit comments

Comments
 (0)