Skip to content

Commit 0f25f02

Browse files
authored
[Macros] Improve diagnostics for missing macro implementation (#65814)
We should no longer say "macro implementation must be provided via '-load-plugin-library'" as there are multiple ways to pick up a macro dependency. Here's an improved version: > warning: external macro implementation type 'MissingModule.MissingType' could not be found for macro 'missingMacro1'; the type must be public and provided by a macro target in a Swift package, or via '-plugin-path' or '-load-plugin-library'
1 parent 6c299ad commit 0f25f02

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7039,8 +7039,9 @@ ERROR(macro_undefined,PointsToFirstBadToken,
70397039
"no macro named %0", (Identifier))
70407040
ERROR(external_macro_not_found,none,
70417041
"external macro implementation type '%0.%1' could not be found for "
7042-
"macro %2; the type must be public and provided via "
7043-
"'-load-plugin-library'", (StringRef, StringRef, DeclName))
7042+
"macro %2; the type must be public and provided by a macro target in a "
7043+
"Swift package, or via '-plugin-path' or '-load-plugin-library'",
7044+
(StringRef, StringRef, DeclName))
70447045
ERROR(macro_must_be_defined,none,
70457046
"macro %0 requires a definition", (DeclName))
70467047
ERROR(external_macro_outside_macro_definition,none,

test/Macros/attached_macros_diags.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct SkipNestedType {
3838

3939
// We select the macro, not the property wrapper.
4040
@m1 var x: Int = 0
41-
// expected-error@-1{{external macro implementation type 'MyMacros.Macro1' could not be found for macro 'm1()'; the type must be public and provided via '-load-plugin-library'}}
41+
// expected-error@-1{{external macro implementation type 'MyMacros.Macro1' could not be found for macro 'm1()'}}
4242
}
4343

4444
struct TestMacroArgs {

test/Macros/external-macro-without-decl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: %target-typecheck-verify-swift -swift-version 5 -module-name Swift -parse-stdlib
44

55
// expected-warning@+2{{@expression has been removed in favor of @freestanding(expression)}}
6-
// expected-warning@+1{{external macro implementation type 'A.B' could not be found for macro 'myMacro()'; the type must be public and provided via '-load-plugin-library'}}
6+
// expected-warning@+1{{external macro implementation type 'A.B' could not be found for macro 'myMacro()'}}
77
@expression macro myMacro() = #externalMacro(module: "A", type: "B")
88

99
// Protocols needed for string literals to work

test/Macros/macros_diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func shadow(a: Int, b: Int, stringify: Int) {
137137
}
138138

139139
func testMissing() {
140-
#missingMacro1("hello") // expected-error{{external macro implementation type 'MissingModule.MissingType' could not be found for macro 'missingMacro1'; the type must be public and provided via '-load-plugin-library'}}
140+
#missingMacro1("hello") // expected-error{{external macro implementation type 'MissingModule.MissingType' could not be found for macro 'missingMacro1'; the type must be public and provided by a macro target in a Swift package, or via '-plugin-path' or '-load-plugin-library'}}
141141
}
142142

143143
@freestanding(expression) macro undefined() // expected-error{{macro 'undefined()' requires a definition}}

test/Macros/parsing.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,35 @@ protocol P { }
66
protocol Q { associatedtype Assoc }
77

88
@freestanding(expression) macro m1() -> Int = #externalMacro(module: "A", type: "M1")
9-
// expected-warning@-1{{external macro implementation type 'A.M1' could not be found for macro 'm1()'; the type must be public and provided via '-load-plugin-library'}}
9+
// expected-warning@-1{{external macro implementation type 'A.M1' could not be found for macro 'm1()'}}
1010
// expected-note@-2{{'m1()' declared here}}
1111
@freestanding(expression) macro m2(_: Int) = #externalMacro(module: "A", type: "M2")
12-
// expected-warning@-1{{external macro implementation type 'A.M2' could not be found for macro 'm2'; the type must be public and provided via '-load-plugin-library'}}
12+
// expected-warning@-1{{external macro implementation type 'A.M2' could not be found for macro 'm2'}}
1313
@freestanding(expression) macro m3(a b: Int) -> Int = #externalMacro(module: "A", type: "M3")
14-
// expected-warning@-1{{external macro implementation type 'A.M3' could not be found for macro 'm3(a:)'; the type must be public and provided via '-load-plugin-library'}}
14+
// expected-warning@-1{{external macro implementation type 'A.M3' could not be found for macro 'm3(a:)'}}
1515
@freestanding(expression) macro m4<T: Q>() -> T = #externalMacro(module: "A", type: "M4") where T.Assoc: P
16-
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm4()'; the type must be public and provided via '-load-plugin-library'}}
16+
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm4()'}}
1717
@freestanding(expression) macro m5<T: P>(_: T) = #externalMacro(module: "A", type: "M4")
18-
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm5'; the type must be public and provided via '-load-plugin-library'}}
18+
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm5'}}
1919

2020
@freestanding(expression) macro m6 = A // expected-error{{expected '(' for macro parameters or ':' for a value-like macro}}
2121
// expected-error@-1{{by a macro expansion}}
2222

2323
// expected-error @+2 {{expected '('}}
2424
// expected-error @+1 {{macro 'm7' must declare its applicable roles}}
2525
@freestanding macro m7(_: String) = #externalMacro(module: "A", type: "M4")
26-
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm7'; the type must be public and provided via '-load-plugin-library'}}
26+
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm7'}}
2727

2828
// expected-error @+2 {{expected a freestanding macro role such as 'expression'}}
2929
// expected-error @+1 {{macro 'm8' must declare its applicable roles}}
3030
@freestanding(abc) macro m8(_: String) = #externalMacro(module: "A", type: "M4")
31-
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm8'; the type must be public and provided via '-load-plugin-library'}}
31+
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm8'}}
3232
@freestanding(declaration, names: arbitrary) macro m9(_: String) = #externalMacro(module: "A", type: "M4")
33-
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm9'; the type must be public and provided via '-load-plugin-library'}}
33+
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm9'}}
3434

3535
@freestanding(expression) @freestanding(declaration, names: named(Foo)) @attached(accessor)
3636
macro m10(_: String) = #externalMacro(module: "A", type: "M4")
37-
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm10'; the type must be public and provided via '-load-plugin-library'}}
37+
// expected-warning@-1{{external macro implementation type 'A.M4' could not be found for macro 'm10'}}
3838

3939
@attached(
4040
accessor,
@@ -55,4 +55,4 @@ macro am2() -> Void
5555

5656
#m1 + 1
5757
// expected-warning @-1 {{result of operator '+' is unused}}
58-
// expected-error @-2 {{external macro implementation type 'A.M1' could not be found for macro 'm1()'; the type must be public and provided via '-load-plugin-library'}}
58+
// expected-error @-2 {{external macro implementation type 'A.M1' could not be found for macro 'm1()'}}

0 commit comments

Comments
 (0)