Update tests with diagnostics in macro expansions

This commit is contained in:
Henrik G. Olsson
2025-09-18 16:41:07 -07:00
parent e3d92dbf0f
commit b2069a3e66
10 changed files with 232 additions and 83 deletions

View File

@@ -7,6 +7,11 @@
struct TL { struct TL {
@TaskLocal // expected-note{{in expansion of macro 'TaskLocal' on static property 'number' here}} @TaskLocal // expected-note{{in expansion of macro 'TaskLocal' on static property 'number' here}}
static var number: Int = 0 static var number: Int = 0
/*
expected-expansion@-2:29{{
expected-note@1:8{{change 'let' to 'var' to make it mutable}}
}}
*/
@TaskLocal @TaskLocal
static var someNil: Int? static var someNil: Int?
@@ -14,6 +19,11 @@ struct TL {
// expected-note@+1{{in expansion of macro 'TaskLocal' on static property 'noValue' here}} // expected-note@+1{{in expansion of macro 'TaskLocal' on static property 'noValue' here}}
@TaskLocal // expected-error{{@TaskLocal' property must have default value, or be optional}} @TaskLocal // expected-error{{@TaskLocal' property must have default value, or be optional}}
static var noValue: Int // expected-note{{'noValue' declared here}} static var noValue: Int // expected-note{{'noValue' declared here}}
/*
expected-expansion@-2:26{{
expected-error@3:9{{cannot find '$noValue' in scope; did you mean 'noValue'?}}
}}
*/
@TaskLocal // expected-error{{'@TaskLocal' can only be applied to 'static' property}} @TaskLocal // expected-error{{'@TaskLocal' can only be applied to 'static' property}}
var notStatic: String? var notStatic: String?

View File

@@ -30,6 +30,14 @@ distributed actor Caplin {
protocol Fail: DistributedActor { protocol Fail: DistributedActor {
distributed func method() -> String distributed func method() -> String
} }
/*
expected-expansion@-2:2{{
expected-error@1:19{{distributed actor '$Fail' does not declare ActorSystem it can be used with}}
expected-note@1:13{{you can provide a module-wide default actor system by declaring:}}
expected-error@1:19{{type '$Fail' does not conform to protocol 'DistributedActor'}}
expected-note@1:19{{add stubs for conformance}}
}}
*/
@Resolvable // expected-note2{{in expansion of macro 'Resolvable' on protocol 'SomeRoot' here}} @Resolvable // expected-note2{{in expansion of macro 'Resolvable' on protocol 'SomeRoot' here}}
public protocol SomeRoot: DistributedActor, Sendable public protocol SomeRoot: DistributedActor, Sendable
@@ -39,3 +47,9 @@ public protocol SomeRoot: DistributedActor, Sendable
static var staticValue: String { get } static var staticValue: String { get }
var value: String { get } var value: String { get }
} }
/*
expected-expansion@-2:2{{
expected-error@1:27{{type '$SomeRoot<ActorSystem>' does not conform to protocol 'SomeRoot'}}
expected-note@1:27{{add stubs for conformance}}
}}
*/

View File

@@ -13,8 +13,14 @@ func deprecated() -> Int { 0 }
var globalVar3 = #stringify({ deprecated() }) var globalVar3 = #stringify({ deprecated() })
// expected-note@-1 {{in expansion of macro 'stringify' here}} // expected-note@-1 {{in expansion of macro 'stringify' here}}
// expected-warning@-2{{'deprecated()' is deprecated}} // expected-warning@-2{{'deprecated()' is deprecated}}
// expected-expansion@-3:18{{
// expected-warning@2:9{{'deprecated()' is deprecated}}
// }}
var globalVar4 = #stringify({ deprecated() }) var globalVar4 = #stringify({ deprecated() })
// expected-note@-1 {{in expansion of macro 'stringify' here}} // expected-note@-1 {{in expansion of macro 'stringify' here}}
// expected-warning@-2{{'deprecated()' is deprecated}} // expected-warning@-2{{'deprecated()' is deprecated}}
// expected-expansion@-3:18{{
// expected-warning@2:9{{'deprecated()' is deprecated}}
// }}

View File

@@ -99,6 +99,11 @@ struct MyBrokenStruct {
// expected-note@+1 2{{in expansion of macro 'myPropertyWrapper' on property 'birthDate' here}} // expected-note@+1 2{{in expansion of macro 'myPropertyWrapper' on property 'birthDate' here}}
@myPropertyWrapper @myPropertyWrapper
var birthDate: Date? { var birthDate: Date? {
/*
expected-expansion@-2:25{{
expected-error@1:1{{variable already has a getter}}
}}
*/
// CHECK-DIAGS: variable already has a getter // CHECK-DIAGS: variable already has a getter
// CHECK-DIAGS: in expansion of macro // CHECK-DIAGS: in expansion of macro
// CHECK-DIAGS: previous definition of getter here // CHECK-DIAGS: previous definition of getter here
@@ -153,6 +158,12 @@ struct HasStoredTests {
// expected-error@-1{{expansion of macro 'MakeComputedSneakily()' produced an unexpected getter}} // expected-error@-1{{expansion of macro 'MakeComputedSneakily()' produced an unexpected getter}}
// expected-note@-2 2{{in expansion of macro}} // expected-note@-2 2{{in expansion of macro}}
// expected-note@-3 2{{'z' declared here}} // expected-note@-3 2{{'z' declared here}}
/*
expected-expansion@-5:36{{
expected-error@3:9{{cannot find '_z' in scope; did you mean 'z'?}}
expected-error@6:9{{cannot find '_z' in scope; did you mean 'z'?}}
}}
*/
#endif #endif
} }

View File

@@ -73,11 +73,11 @@ macro NotCovered() = #externalMacro(module: "MacroDefinition", type: "InvalidMac
struct MemberNotCovered { struct MemberNotCovered {
#NotCovered #NotCovered
// expected-note@-1 {{in expansion of macro 'NotCovered' here}} // expected-note@-1 {{in expansion of macro 'NotCovered' here}}
/*
// CHECK-DIAGS: error: declaration name 'value' is not covered by macro 'NotCovered' expected-expansion@-3:3 {{
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX[[@LINE-5]]_2_33_4361AD9339943F52AE6186DD51E04E91Ll10NotCoveredfMf_.swift expected-error@1:5{{declaration name 'value' is not covered by macro 'NotCovered'}}
// CHECK-DIAGS: var value: Int }}
// CHECK-DIAGS: END CONTENTS OF FILE */
} }
@attached(peer) @attached(peer)
@@ -86,24 +86,29 @@ macro Invalid() = #externalMacro(module: "MacroDefinition", type: "InvalidMacro"
@Invalid @Invalid
struct Bad {} struct Bad {}
// expected-note@-2 18 {{in expansion of macro 'Invalid' on struct 'Bad' here}} // expected-note@-2 18 {{in expansion of macro 'Invalid' on struct 'Bad' here}}
/*
expected-expansion@-3:14 {{
expected-error@1:8{{macro expansion cannot introduce import}}
expected-error@3:17{{macro expansion cannot introduce precedence group}}
expected-error@6:25{{macro 'myMacro()' requires a definition}}
expected-error@6:25{{macro expansion cannot introduce macro}}
expected-error@8:1{{macro expansion cannot introduce extension}}
expected-error@11:1{{macro expansion cannot introduce '@main' type}}
expected-error@12:8{{declaration name 'MyMain' is not covered by macro 'Invalid'}}
expected-error@17:11{{declaration name 'Array' is not covered by macro 'Invalid'}}
expected-error@19:11{{declaration name 'Dictionary' is not covered by macro 'Invalid'}}
expected-error@21:11{{macro expansion cannot introduce default literal type 'BooleanLiteralType'}}
expected-error@23:11{{macro expansion cannot introduce default literal type 'ExtendedGraphemeClusterType'}}
expected-error@25:11{{macro expansion cannot introduce default literal type 'FloatLiteralType'}}
expected-error@27:11{{macro expansion cannot introduce default literal type 'IntegerLiteralType'}}
expected-error@29:11{{macro expansion cannot introduce default literal type 'StringLiteralType'}}
expected-error@31:11{{macro expansion cannot introduce default literal type 'UnicodeScalarType'}}
expected-error@33:11{{macro expansion cannot introduce default literal type '_ColorLiteralType'}}
expected-error@35:11{{macro expansion cannot introduce default literal type '_ImageLiteralType'}}
expected-error@37:11{{macro expansion cannot introduce default literal type '_FileReferenceLiteralType'}}
}}
*/
// CHECK-DIAGS: error: macro expansion cannot introduce import
// CHECK-DIAGS: error: macro expansion cannot introduce precedence group
// CHECK-DIAGS: error: macro expansion cannot introduce macro
// CHECK-DIAGS: error: macro expansion cannot introduce extension
// CHECK-DIAGS: error: macro expansion cannot introduce '@main' type
// CHECK-DIAGS: error: declaration name 'MyMain' is not covered by macro 'Invalid'
// CHECK-DIAGS: error: declaration name 'Array' is not covered by macro 'Invalid'
// CHECK-DIAGS: error: declaration name 'Dictionary' is not covered by macro 'Invalid'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type 'BooleanLiteralType'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type 'ExtendedGraphemeClusterType'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type 'FloatLiteralType'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type 'IntegerLiteralType'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type 'StringLiteralType'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type 'UnicodeScalarType'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type '_ColorLiteralType'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type '_ImageLiteralType'
// CHECK-DIAGS: error: macro expansion cannot introduce default literal type '_FileReferenceLiteralType'
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser3Bad7InvalidfMp_.swift // CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser3Bad7InvalidfMp_.swift
// CHECK-DIAGS: import Swift // CHECK-DIAGS: import Swift
@@ -132,21 +137,28 @@ struct Bad {}
class HasStoredPropertyClassInvalid { class HasStoredPropertyClassInvalid {
#AddStoredProperty((Self.self, 0).1) // expected-note {{in expansion of macro 'AddStoredProperty' here}} #AddStoredProperty((Self.self, 0).1) // expected-note {{in expansion of macro 'AddStoredProperty' here}}
// CHECK-DIAGS: @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX[[@LINE-2]]_2_33_{{.*}}AddStoredPropertyfMf_.swift:1:22: error: covariant 'Self' type cannot be referenced from a stored property initializer /*
expected-expansion@-2:3 {{
expected-error@1:22{{covariant 'Self' type cannot be referenced from a stored property initializer}}
}}
*/
} }
// Redeclaration checking should behave as though expansions are part of the // Redeclaration checking should behave as though expansions are part of the
// source file. // source file.
struct RedeclChecking { struct RedeclChecking {
#varValue #varValue
/*
expected-expansion@-2:3 {{
expected-note@1:5{{'value' previously declared here}}
}}
*/
// expected-error@+1 {{invalid redeclaration of 'value'}} // expected-error@+1 {{invalid redeclaration of 'value'}}
var value: Int { 0 } var value: Int { 0 }
} }
// CHECK-DIAGS: macro_expand.swift:[[@LINE-3]]:7: error: invalid redeclaration of 'value' // CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX[[@LINE-12]]_2_33_4361AD9339943F52AE6186DD51E04E91Ll8varValuefMf_.swift:
// CHECK-DIAGS: @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX[[@LINE-8]]_2_33_4361AD9339943F52AE6186DD51E04E91Ll8varValuefMf_.swift:1:5: note: 'value' previously declared here
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX[[@LINE-9]]_2_33_4361AD9339943F52AE6186DD51E04E91Ll8varValuefMf_.swift:
// CHECK-DIAGS: var value: Int { // CHECK-DIAGS: var value: Int {
// CHECK-DIAGS: 1 // CHECK-DIAGS: 1
// CHECK-DIAGS: } // CHECK-DIAGS: }
@@ -159,11 +171,19 @@ public macro ThrowCancellation() = #externalMacro(module: "MacroDefinition", typ
// error mismatch. // error mismatch.
@ThrowCancellation // expected-note {{in expansion of macro 'ThrowCancellation' on global function 'issue79039()' here}} @ThrowCancellation // expected-note {{in expansion of macro 'ThrowCancellation' on global function 'issue79039()' here}}
func issue79039() throws(DecodingError) func issue79039() throws(DecodingError)
// CHECK-DIAGS: @__swiftmacro_9MacroUser10issue7903917ThrowCancellationfMb_.swift:2:11: error: thrown expression type 'CancellationError' cannot be converted to error type 'DecodingError' /*
expected-expansion@-2:39 {{
expected-error@2:11{{thrown expression type 'CancellationError' cannot be converted to error type 'DecodingError'}}
}}
*/
@ThrowCancellation // expected-note {{in expansion of macro 'ThrowCancellation' on global function 'issue79039_2()' here}} @ThrowCancellation // expected-note {{in expansion of macro 'ThrowCancellation' on global function 'issue79039_2()' here}}
func issue79039_2() throws(DecodingError) {} func issue79039_2() throws(DecodingError) {}
// CHECK-DIAGS: @__swiftmacro_9MacroUser12issue79039_217ThrowCancellationfMb_.swift:2:11: error: thrown expression type 'CancellationError' cannot be converted to error type 'DecodingError' /*
expected-expansion@-2:43 {{
expected-error@2:11{{thrown expression type 'CancellationError' cannot be converted to error type 'DecodingError'}}
}}
*/
#endif #endif
@freestanding(declaration) @freestanding(declaration)
@@ -176,16 +196,28 @@ macro AccidentalCodeItem() = #externalMacro(module: "MacroDefinition", type: "Fa
func invalidDeclarationMacro() { func invalidDeclarationMacro() {
#accidentalCodeItem #accidentalCodeItem
// expected-note@-1 {{in expansion of macro 'accidentalCodeItem' here}} // expected-note@-1 {{in expansion of macro 'accidentalCodeItem' here}}
// CHECK-DIAGS: @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX[[@LINE-3]]_2_18accidentalCodeItemfMf_.swift:1:1: error: expected macro expansion to produce a declaration /*
expected-expansion@-3:3 {{
expected-error@1:1{{expected macro expansion to produce a declaration}}
}}
*/
@AccidentalCodeItem struct S {} @AccidentalCodeItem struct S {}
// expected-note@-1 {{in expansion of macro 'AccidentalCodeItem' on struct 'S' here}} // expected-note@-1 {{in expansion of macro 'AccidentalCodeItem' on struct 'S' here}}
// CHECK-DIAGS: @__swiftmacro_9MacroUser018invalidDeclarationA0yyF5S_$l018AccidentalCodeItemfMp_.swift:1:1: error: expected macro expansion to produce a declaration /*
expected-expansion@-3:34 {{
expected-error@1:1{{expected macro expansion to produce a declaration}}
}}
*/
do { do {
@AccidentalCodeItem struct S {} @AccidentalCodeItem struct S {}
// expected-note@-1 {{in expansion of macro 'AccidentalCodeItem' on struct 'S' here}} // expected-note@-1 {{in expansion of macro 'AccidentalCodeItem' on struct 'S' here}}
// CHECK-DIAGS: @__swiftmacro_9MacroUser018invalidDeclarationA0yyF5S_$l118AccidentalCodeItemfMp_.swift:1:1: error: expected macro expansion to produce a declaration /*
expected-expansion@-3:36 {{
expected-error@1:1{{expected macro expansion to produce a declaration}}
}}
*/
} }
} }
#endif #endif
@@ -323,9 +355,14 @@ func testNested() {
struct Nested { } struct Nested { }
_ = #stringify(#assertAny(Nested())) _ = #stringify(#assertAny(Nested()))
// expected-note@-1 {{in expansion of macro 'stringify' here}} // expected-note@-1 {{in expansion of macro 'stringify' here}}
// CHECK-DIAGS-NOT: error: cannot convert value of type 'Nested' to expected argument type 'Bool' /*
// CHECK-DIAGS: @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX{{.*}}_9stringifyfMf_9assertAnyfMf_.swift:1:8: error: cannot convert value of type 'Nested' to expected argument type 'Bool' expected-expansion@-3:7 {{
// CHECK-DIAGS-NOT: error: cannot convert value of type 'Nested' to expected argument type 'Bool' expected-note@1:2{{in expansion of macro 'assertAny' here}}
expected-expansion@1:2{{
expected-error@1:8{{cannot convert value of type 'Nested' to expected argument type 'Bool'}}
}}
}}
*/
// PRETTY-DIAGS: 1:8: error: cannot convert value of type 'Nested' to expected argument type 'Bool' // PRETTY-DIAGS: 1:8: error: cannot convert value of type 'Nested' to expected argument type 'Bool'
// PRETTY-DIAGS: macro_expand.swift:{{.*}}:39: note: expanded code originates here // PRETTY-DIAGS: macro_expand.swift:{{.*}}:39: note: expanded code originates here
@@ -344,8 +381,15 @@ func testStringifyWithThrows() throws {
#if TEST_DIAGNOSTICS #if TEST_DIAGNOSTICS
// FIXME: Lots of duplicate notes here // FIXME: Lots of duplicate notes here
_ = #stringify(maybeThrowing()) // expected-note 4{{in expansion of macro 'stringify' here}} _ = #stringify(maybeThrowing()) // expected-note 4{{in expansion of macro 'stringify' here}}
/*
expected-expansion@-2:7 {{
expected-error@1:2{{call can throw but is not marked with 'try'}}
expected-note@1:2{{did you mean to disable error propagation?}}
expected-note@1:2{{did you mean to handle error as optional value?}}
expected-note@1:2{{did you mean to use 'try'?}}
}}
*/
// CHECK-DIAGS: @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX{{.*}}_9stringifyfMf1_.swift:1:2: error: call can throw but is not marked with 'try'
#endif #endif
// The macro adds the 'try' for us. // The macro adds the 'try' for us.
@@ -385,14 +429,18 @@ func testAddBlocker(a: Int, b: Int, c: Int, oa: OnlyAdds) {
_ = #addBlocker(oa + oa) // expected-error{{blocked an add; did you mean to subtract? (from macro 'addBlocker')}} _ = #addBlocker(oa + oa) // expected-error{{blocked an add; did you mean to subtract? (from macro 'addBlocker')}}
// expected-note@-1{{in expansion of macro 'addBlocker' here}} // expected-note@-1{{in expansion of macro 'addBlocker' here}}
// expected-note@-2{{use '-'}}{{22-23=-}} // expected-note@-2{{use '-'}}{{22-23=-}}
/*
// CHECK-DIAGS: @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX{{.*}}_10addBlockerfMf1_.swift:1:4: error: binary operator '-' cannot be applied to two 'OnlyAdds' operands [] [] expected-expansion@-4:7 {{
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX{{.*}}_10addBlockerfMf1_.swift: expected-error@1:4{{binary operator '-' cannot be applied to two 'OnlyAdds' operands}}
// CHECK-DIAGS-NEXT: Original source range: {{.*}}macro_expand.swift:[[@LINE-6]]:7 - {{.*}}macro_expand.swift:[[@LINE-6]]:27 }}
// CHECK-DIAGS-NEXT: oa - oa */
// CHECK-DIAGS-NEXT: END CONTENTS OF FILE
_ = #addBlocker({ // expected-note{{in expansion of macro 'addBlocker' here}} _ = #addBlocker({ // expected-note{{in expansion of macro 'addBlocker' here}}
/*
expected-expansion@-2:7 {{
expected-error@9:16{{referencing operator function '-' on 'FloatingPoint' requires that 'OnlyAdds' conform to 'FloatingPoint'}}
}}
*/
print("hello") print("hello")
print(oa + oa) // expected-error{{blocked an add; did you mean to subtract? (from macro 'addBlocker')}} print(oa + oa) // expected-error{{blocked an add; did you mean to subtract? (from macro 'addBlocker')}}
@@ -403,7 +451,13 @@ func testAddBlocker(a: Int, b: Int, c: Int, oa: OnlyAdds) {
// Check recursion. // Check recursion.
#recurse(false) // okay #recurse(false) // okay
#recurse(true) // expected-note{{in expansion of macro 'recurse' here}} #recurse(true)
/*
expected-expansion@-2:3 {{
expected-error@1:1{{recursive expansion of macro 'recurse'}}
}}
expected-note@-5{{in expansion of macro 'recurse' here}}
*/
#endif #endif
} }
@@ -494,6 +548,14 @@ func testFreestandingMacroExpansion() {
struct Foo3 { struct Foo3 {
#bitwidthNumberedStructs("BUG", blah: false) #bitwidthNumberedStructs("BUG", blah: false)
// expected-note@-1 4{{in expansion of macro 'bitwidthNumberedStructs' here}} // expected-note@-1 4{{in expansion of macro 'bitwidthNumberedStructs' here}}
/*
expected-expansion@-3:5 {{
expected-error@3:14{{unexpected non-void return value in void function}}
expected-note@3:14{{did you mean to add a return type?}}
expected-error@6:14{{unexpected non-void return value in void function}}
expected-note@6:14{{did you mean to add a return type?}}
}}
*/
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX{{.*}}_23bitwidthNumberedStructsfMf_.swift // CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX{{.*}}_23bitwidthNumberedStructsfMf_.swift
// CHECK-DIAGS: struct BUG { // CHECK-DIAGS: struct BUG {
// CHECK-DIAGS: func $s9MacroUser0023macro_expandswift_elFCffMX{{.*}}_23bitwidthNumberedStructsfMf_6methodfMu_() // CHECK-DIAGS: func $s9MacroUser0023macro_expandswift_elFCffMX{{.*}}_23bitwidthNumberedStructsfMf_6methodfMu_()
@@ -727,6 +789,11 @@ struct ABIAttrWithFreestandingMacro1 {
@abi(#varValue) @abi(#varValue)
#varValue #varValue
// expected-note@-1 {{in expansion of macro 'varValue' here}} // expected-note@-1 {{in expansion of macro 'varValue' here}}
/*
expected-expansion@-3:3 {{
expected-error@2:6{{cannot use pound literal in '@abi'}}
}}
*/
} }
struct ABIAttrWithFreestandingMacro2 { struct ABIAttrWithFreestandingMacro2 {
@@ -759,7 +826,11 @@ func invalidDeclarationMacro2() {
func f() { func f() {
#accidentalCodeItem #accidentalCodeItem
// expected-note@-1 {{in expansion of macro 'accidentalCodeItem' here}} // expected-note@-1 {{in expansion of macro 'accidentalCodeItem' here}}
// CHECK-DIAGS: @__swiftmacro_9MacroUser0023macro_expandswift_elFCffMX[[@LINE-3]]_6_18accidentalCodeItemfMf_.swift:1:1: error: expected macro expansion to produce a declaration /*
expected-expansion@-3:7 {{
expected-error@1:1{{expected macro expansion to produce a declaration}}
}}
*/
} }
} }
} }

View File

@@ -10,9 +10,6 @@
// RUN: %FileCheck -check-prefix=CHECK-DUMP %s < %t/expansions-dump.txt // RUN: %FileCheck -check-prefix=CHECK-DUMP %s < %t/expansions-dump.txt
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -swift-version 5 -I %t // RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -swift-version 5 -I %t
// RUN: not %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -serialize-diagnostics-path %t/macro_expand.dia %s -emit-macro-expansion-files no-diagnostics
// RUN: c-index-test -read-diagnostics %t/macro_expand.dia 2>&1 | %FileCheck -check-prefix CHECK-DIAGS %s
// Ensure that we can serialize this file as a module. // Ensure that we can serialize this file as a module.
// RUN: %target-swift-frontend -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking -emit-module -o %t/MyModule.swiftmodule -enable-testing // RUN: %target-swift-frontend -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking -emit-module -o %t/MyModule.swiftmodule -enable-testing
@@ -137,8 +134,11 @@ macro UndocumentedNamesInExtension() = #externalMacro(module: "MacroDefinition",
@UndocumentedNamesInExtension @UndocumentedNamesInExtension
struct S<Element> {} struct S<Element> {}
// expected-note@-2 {{in expansion of macro 'UndocumentedNamesInExtension' on generic struct 'S' here}} // expected-note@-2 {{in expansion of macro 'UndocumentedNamesInExtension' on generic struct 'S' here}}
/*
// CHECK-DIAGS: error: declaration name 'requirement()' is not covered by macro 'UndocumentedNamesInExtension' expected-expansion@-3:21 {{
expected-error@2:15{{declaration name 'requirement()' is not covered by macro 'UndocumentedNamesInExtension'}}
}}
*/
@attached(extension, names: named(requirement)) @attached(extension, names: named(requirement))
macro UndocumentedConformanceInExtension() = #externalMacro(module: "MacroDefinition", type: "AlwaysAddConformance") macro UndocumentedConformanceInExtension() = #externalMacro(module: "MacroDefinition", type: "AlwaysAddConformance")
@@ -146,8 +146,11 @@ macro UndocumentedConformanceInExtension() = #externalMacro(module: "MacroDefini
@UndocumentedConformanceInExtension @UndocumentedConformanceInExtension
struct InvalidConformance<Element> {} struct InvalidConformance<Element> {}
// expected-note@-2 {{in expansion of macro 'UndocumentedConformanceInExtension' on generic struct 'InvalidConformance' here}} // expected-note@-2 {{in expansion of macro 'UndocumentedConformanceInExtension' on generic struct 'InvalidConformance' here}}
/*
// CHECK-DIAGS: error: conformance to 'P' is not covered by macro 'UndocumentedConformanceInExtension' expected-expansion@-3:38 {{
expected-error@1:1{{conformance to 'P' is not covered by macro 'UndocumentedConformanceInExtension'}}
}}
*/
@attached(extension) @attached(extension)
macro UndocumentedCodable() = #externalMacro(module: "MacroDefinition", type: "AlwaysAddCodable") macro UndocumentedCodable() = #externalMacro(module: "MacroDefinition", type: "AlwaysAddCodable")
@@ -155,8 +158,11 @@ macro UndocumentedCodable() = #externalMacro(module: "MacroDefinition", type: "A
@UndocumentedCodable @UndocumentedCodable
struct TestUndocumentedCodable {} struct TestUndocumentedCodable {}
// expected-note@-2 {{in expansion of macro 'UndocumentedCodable' on struct 'TestUndocumentedCodable' here}} // expected-note@-2 {{in expansion of macro 'UndocumentedCodable' on struct 'TestUndocumentedCodable' here}}
/*
// CHECK-DIAGS: error: conformance to 'Codable' (aka 'Decodable & Encodable') is not covered by macro 'UndocumentedCodable' expected-expansion@-3:34 {{
expected-error@1:1{{conformance to 'Codable' (aka 'Decodable & Encodable') is not covered by macro 'UndocumentedCodable'}}
}}
*/
@attached(extension, conformances: Decodable) @attached(extension, conformances: Decodable)
macro UndocumentedEncodable() = #externalMacro(module: "MacroDefinition", type: "AlwaysAddCodable") macro UndocumentedEncodable() = #externalMacro(module: "MacroDefinition", type: "AlwaysAddCodable")
@@ -164,8 +170,11 @@ macro UndocumentedEncodable() = #externalMacro(module: "MacroDefinition", type:
@UndocumentedEncodable @UndocumentedEncodable
struct TestUndocumentedEncodable {} struct TestUndocumentedEncodable {}
// expected-note@-2 {{in expansion of macro 'UndocumentedEncodable' on struct 'TestUndocumentedEncodable' here}} // expected-note@-2 {{in expansion of macro 'UndocumentedEncodable' on struct 'TestUndocumentedEncodable' here}}
/*
// CHECK-DIAGS: error: conformance to 'Codable' (aka 'Decodable & Encodable') is not covered by macro 'UndocumentedEncodable' expected-expansion@-3:36 {{
expected-error@1:1{{conformance to 'Codable' (aka 'Decodable & Encodable') is not covered by macro 'UndocumentedEncodable'}}
}}
*/
@attached(extension) @attached(extension)
macro BadExtension() = #externalMacro(module: "MacroDefinition", type: "BadExtensionMacro") macro BadExtension() = #externalMacro(module: "MacroDefinition", type: "BadExtensionMacro")
@@ -176,7 +185,11 @@ struct HasSomeNestedType {
@BadExtension // expected-note {{in expansion of macro 'BadExtension' on struct 'SomeNestedType' here}} @BadExtension // expected-note {{in expansion of macro 'BadExtension' on struct 'SomeNestedType' here}}
struct SomeNestedType {} struct SomeNestedType {}
} }
// CHECK-DIAGS: error: cannot find type 'SomeNestedType' in scope /*
expected-expansion@-2:2 {{
expected-error@1:11{{cannot find type 'SomeNestedType' in scope}}
}}
*/
#endif #endif

View File

@@ -32,7 +32,15 @@ func testFreestandingExpansionOfOther() {
#if TEST_DIAGNOSTICS #if TEST_DIAGNOSTICS
#recurseThrough(true) #recurseThrough(true)
// expected-note@-1 {{in expansion of macro 'recurseThrough' here}} /*
expected-expansion@-2:1{{
expected-expansion@1:1{{
expected-error@1:1{{recursive expansion of macro 'recurse'}}
}}
expected-note@1:1{{in expansion of macro 'recurse' here}}
}}
expected-note@-8 {{in expansion of macro 'recurseThrough' here}}
*/
#endif #endif
} }

View File

@@ -317,9 +317,15 @@ struct ABIAttrWithAttachedMacro {
// expected-error@+1 {{macro 'addCompletionHandler()' cannot be expanded in '@abi' attribute}} // expected-error@+1 {{macro 'addCompletionHandler()' cannot be expanded in '@abi' attribute}}
@abi(@addCompletionHandler func fn1() async) @abi(@addCompletionHandler func fn1() async)
@addCompletionHandler func fn1() async {} @addCompletionHandler func fn1() async {}
// From diagnostics in the expansion: /*
// expected-note@-2 3{{in expansion of macro 'addCompletionHandler' on instance method 'fn1()' here}} expected-expansion@-2:44{{
// expected-note@-4 {{'fn1()' previously declared here}} expected-error@2:8{{macro 'addCompletionHandler()' cannot be expanded in '@abi' attribute}}
expected-error@2:35{{invalid redeclaration of 'fn1()'}}
expected-error@4:23{{argument passed to call that takes no arguments}}
}}
expected-note@-7 3{{in expansion of macro 'addCompletionHandler' on instance method 'fn1()' here}}
expected-note@-9 {{'fn1()' previously declared here}}
*/
// expected-error@+1 {{macro 'addCompletionHandler()' cannot be expanded in '@abi' attribute}} // expected-error@+1 {{macro 'addCompletionHandler()' cannot be expanded in '@abi' attribute}}
@abi(@addCompletionHandler func fn2() async) @abi(@addCompletionHandler func fn2() async)
@@ -327,8 +333,13 @@ struct ABIAttrWithAttachedMacro {
@abi(func fn3() async) @abi(func fn3() async)
@addCompletionHandler func fn3() async {} @addCompletionHandler func fn3() async {}
// From diagnostics in the expansion: /*
// expected-note@-2 2{{in expansion of macro 'addCompletionHandler' on instance method 'fn3()' here}} expected-expansion@-2:44{{
// expected-note@-4 {{'fn3()' previously declared here}} expected-error@1:11{{invalid redeclaration of 'fn3()'}}
expected-error@3:23{{argument passed to call that takes no arguments}}
}}
expected-note@-6 2{{in expansion of macro 'addCompletionHandler' on instance method 'fn3()' here}}
expected-note@-8 {{'fn3()' previously declared here}}
*/
} }
#endif #endif

View File

@@ -105,12 +105,17 @@ print(ElementType.paper.unknown())
#if TEST_DIAGNOSTICS #if TEST_DIAGNOSTICS
@addMembersQuotedInit @addMembersQuotedInit
struct S2 { struct S2 {
// expected-note@-2 {{in expansion of macro 'addMembersQuotedInit' on struct 'S2' here}}
func useSynthesized() { func useSynthesized() {
S.method() S.method()
print(type(of: getStorage())) print(type(of: getStorage()))
} }
} }
/*
expected-expansion@-2:1{{
expected-error@14:1{{declaration name 'init()' is not covered by macro 'addMembersQuotedInit'}}
}}
expected-note@-11 {{in expansion of macro 'addMembersQuotedInit' on struct 'S2' here}}
*/
#endif #endif
@attached( @attached(

View File

@@ -12,10 +12,6 @@
// RUN: %target-typecheck-verify-swift -swift-version 5 -parse-as-library -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -DIMPORT_MACRO_LIBRARY -swift-version 5 %S/Inputs/top_level_freestanding_other.swift -I %t // RUN: %target-typecheck-verify-swift -swift-version 5 -parse-as-library -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -DIMPORT_MACRO_LIBRARY -swift-version 5 %S/Inputs/top_level_freestanding_other.swift -I %t
// Check diagnostic buffer names
// RUN: not %target-swift-frontend -typecheck -swift-version 5 -parse-as-library -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -swift-version 5 %s %S/Inputs/top_level_freestanding_other.swift -diagnostic-style llvm 2> %t.diags
// RUN: %FileCheck -check-prefix DIAG_BUFFERS %s < %t.diags
// Execution testing // Execution testing
// RUN: %target-build-swift -g -swift-version 5 -parse-as-library -load-plugin-library %t/%target-library-name(MacroDefinition) %s %S/Inputs/top_level_freestanding_other.swift -o %t/main -module-name MacroUser -swift-version 5 // RUN: %target-build-swift -g -swift-version 5 -parse-as-library -load-plugin-library %t/%target-library-name(MacroDefinition) %s %S/Inputs/top_level_freestanding_other.swift -o %t/main -module-name MacroUser -swift-version 5
// RUN: %target-codesign %t/main // RUN: %target-codesign %t/main
@@ -60,7 +56,7 @@ func lookupGlobalFreestandingExpansion() {
#anonymousTypes(public: true) { "hello" } #anonymousTypes(public: true) { "hello" }
// CHECK-SIL: sil @$s9MacroUser03$s9A115User0033top_level_freestandingswift_DbGHjfMX60_0_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf_4namefMu_C5helloSSyF // CHECK-SIL: sil @$s9MacroUser03$s9A115User0033top_level_freestandingswift_DbGHjfMX56_0_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf_4namefMu_C5helloSSyF
@main @main
struct Main { struct Main {
@@ -94,8 +90,6 @@ func testArbitraryAtGlobal() {
} }
#endif #endif
// expected-warning@@__swiftmacro_9MacroUser0039top_level_freestanding_otherswift_jrGEmfMX12_17_33_7FDB3F9D78D0279543373AD342C3C331Ll9stringifyfMf1_.swift:2:9{{'deprecated()' is deprecated}}
// expected-warning@@__swiftmacro_9MacroUser0039top_level_freestanding_otherswift_jrGEmfMX16_17_33_7FDB3F9D78D0279543373AD342C3C331Ll9stringifyfMf2_.swift:2:9{{'deprecated()' is deprecated}}
#varValue #varValue
@@ -106,26 +100,32 @@ func testGlobalVariable() {
#if TEST_DIAGNOSTICS #if TEST_DIAGNOSTICS
// expected-note @+1 6 {{in expansion of macro 'anonymousTypes' here}} // expected-note @+1 6 {{in expansion of macro 'anonymousTypes' here}}
// expected-note@@__swiftmacro_9MacroUser0033top_level_freestandingswift_DbGHjfMX109_0_33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_.swift:24:3 3{{in expansion of macro 'introduceTypeCheckingErrors' here}}
#anonymousTypes(causeErrors: true) { "foo" } #anonymousTypes(causeErrors: true) { "foo" }
// expected-expansion@-1 {{ /*
// expected-warning@23:8{{same-type requirement makes generic parameter 'T' non-generic; this is an error in the Swift 6 language mode}} expected-expansion@-2:1 {{
// expected-note@23:135{{'T' previously declared here}} expected-warning@23:8{{same-type requirement makes generic parameter 'T' non-generic; this is an error in the Swift 6 language mode}}
// expected-warning@23:149{{use of protocol 'Equatable' as a type must be written 'any Equatable'}} expected-note@23:135{{'T' previously declared here}}
expected-warning@23:149{{use of protocol 'Equatable' as a type must be written 'any Equatable'; this will be an error in a future Swift language mode}}
// expected-warning@5:16{{use of protocol 'Equatable' as a type must be written 'any Equatable'}} expected-note@24:3 3{{in expansion of macro 'introduceTypeCheckingErrors' here}}
// expected-warning@20:16{{use of protocol 'Equatable' as a type must be written 'any Equatable'}} expected-expansion@24:3 {{
// expected-warning@2:273{{use of protocol 'Hashable' as a type must be written 'any Hashable'}} expected-warning@2:10{{same-type requirement makes generic parameter 'T' non-generic; this is an error in the Swift 6 language mode}}
expected-warning@2:259{{generic parameter 'T' shadows generic parameter from outer scope with the same name; this is an error in the Swift 6 language mode}}
// expected-warning@2:10{{same-type requirement makes generic parameter 'T' non-generic; this is an error in the Swift 6 language mode}} expected-warning@2:273{{use of protocol 'Hashable' as a type must be written 'any Hashable'; this will be an error in a future Swift language mode}}
// expected-warning@2:259{{generic parameter 'T' shadows generic parameter from outer scope with the same name; this is an error in the Swift 6 language mode}} }}
// }} }}
*/
// expected-note @+1 2 {{in expansion of macro 'anonymousTypes' here}} // expected-note @+1 2 {{in expansion of macro 'anonymousTypes' here}}
#anonymousTypes { () -> String in #anonymousTypes { () -> String in
// expected-warning @+1 {{use of protocol 'Equatable' as a type must be written 'any Equatable'}} // expected-warning @+1 {{use of protocol 'Equatable' as a type must be written 'any Equatable'}}
_ = 0 as Equatable _ = 0 as Equatable
return "foo" return "foo"
} }
/*
expected-expansion@-6:1{{
expected-warning@5:16{{use of protocol 'Equatable' as a type must be written 'any Equatable'; this will be an error in a future Swift language mode}}
expected-warning@20:16{{use of protocol 'Equatable' as a type must be written 'any Equatable'; this will be an error in a future Swift language mode}}
}}
*/
#endif #endif