Skip to content

Commit 37a67a4

Browse files
committed
[Legacy parser] No freestanding macros in @abi (macro tests)
Additional tests for the previous commit “[Legacy parser] No freestanding macros in `@abi`”.
1 parent 97f80a8 commit 37a67a4

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

test/Macros/macro_expand.swift

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
// REQUIRES: swift_swift_parser, executable_test
2+
// REQUIRES: swift_feature_ABIAttribute
23

34
// RUN: %empty-directory(%t)
45
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift
56

67
// Diagnostics testing
7-
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS
8+
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -enable-experimental-feature ABIAttribute
89

910
// Diagnostics testing by importing macros from a module
1011
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/freestanding_macro_library.swiftmodule %S/Inputs/freestanding_macro_library.swift -module-name freestanding_macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
1112
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/freestanding_macro_library_2.swiftmodule %S/Inputs/freestanding_macro_library_2.swift -module-name freestanding_macro_library_2 -load-plugin-library %t/%target-library-name(MacroDefinition) -I %t
1213

13-
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -I %t -DIMPORT_MACRO_LIBRARY
14+
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -I %t -DIMPORT_MACRO_LIBRARY -enable-experimental-feature ABIAttribute
1415

15-
// 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 -Rmacro-loading > %t/macro-printing.txt
16+
// 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 -Rmacro-loading > %t/macro-printing.txt -enable-experimental-feature ABIAttribute
1617
// RUN: c-index-test -read-diagnostics %t/macro_expand.dia 2>&1 | %FileCheck -check-prefix CHECK-DIAGS -dump-input=always %s
1718

1819
// RUN: %FileCheck %s --check-prefix CHECK-MACRO-PRINTED < %t/macro-printing.txt
1920

20-
// RUN: not %target-swift-frontend -swift-version 5 -typecheck -diagnostic-style=swift -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS %s > %t/pretty-macro-diagnostics.txt 2>&1
21+
// RUN: not %target-swift-frontend -swift-version 5 -typecheck -diagnostic-style=swift -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS %s -enable-experimental-feature ABIAttribute > %t/pretty-macro-diagnostics.txt 2>&1
2122
// RUN: %FileCheck %s --check-prefix PRETTY-DIAGS < %t/pretty-macro-diagnostics.txt
2223

2324
// Debug info SIL testing
@@ -707,6 +708,29 @@ func testPropertyWrapperMacro() {
707708
#hasPropertyWrapperParam($x: .init(wrappedValue: 0))
708709
}
709710

711+
#if swift(>=1.0) && TEST_DIAGNOSTICS
712+
// Test that macros can't be used in @abi
713+
714+
struct ABIAttrWithFreestandingMacro1 {
715+
// expected-error@+1 {{cannot use pound literal in '@abi'}}
716+
@abi(#varValue)
717+
#varValue
718+
// expected-note@-1 {{in expansion of macro 'varValue' here}}
719+
}
720+
721+
struct ABIAttrWithFreestandingMacro2 {
722+
// expected-error@+1 {{cannot use pound literal in '@abi'}}
723+
@abi(#varValue)
724+
var value: Int { 0 }
725+
}
726+
727+
struct ABIAttrWithFreestandingMacro3 {
728+
@abi(var value: Int)
729+
#varValue
730+
}
731+
732+
#endif
733+
710734
#if TEST_DIAGNOSTICS
711735
@freestanding(expression)
712736
macro missingMacro() = #externalMacro(module: "MacroDefinition", type: "BluhBlah")

0 commit comments

Comments
 (0)