Files
swift-mirror/test/Serialization/macros.swift
Doug Gregor 5d6746d974 Improve checking of macro-generated accessors against documented names
The checking of the accessors generated by a macro against the
documented set of accessors for the macro is slightly too strict and
produces misleading error messages. Make the check slightly looser in
the case where an observer-producing macro (such as
`@ObservationIgnored`) is applied to a computed property. Here, we
would diagnose that the observer did not in fact produce any
observers, even though it couldn't have: computed properties don't get
observers. Remove the diagnostic in this case.

While here, add some tests and improve the wording of diagnostics a
bit.

Fixes rdar://113710199.
2023-08-17 16:59:42 -07:00

36 lines
1.5 KiB
Swift

// REQUIRES: swift_swift_parser, asserts
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t-scratch)
// RUN: %host-build-swift -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/def_macro_plugin.swift -g -no-toolchain-stdlib-rpath
// RUN: %target-swift-frontend -emit-module -o %t/def_macros.swiftmodule %S/Inputs/def_macros.swift -module-name def_macros -enable-experimental-feature ExtensionMacros -load-plugin-library %t/%target-library-name(MacroDefinition)
// RUN: %target-swift-frontend -typecheck -I%t -verify %s -verify-ignore-unknown -enable-experimental-feature ExtensionMacros -load-plugin-library %t/%target-library-name(MacroDefinition)
// RUN: llvm-bcanalyzer %t/def_macros.swiftmodule | %FileCheck %s
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -module-to-print=def_macros -I %t -source-filename=%s | %FileCheck -check-prefix=CHECK-PRINT %s
import def_macros
func test(a: Int, b: Int) {
_ = #publicStringify(a + b)
_ = #publicStringify(a + b, label: "hello")
_ = #unlabeledStringify(a + b)
_ = #internalStringify(a + b)
// expected-error@-1{{no macro named 'internalStringify'}}
}
struct TestStruct {
@myWrapper var x: Int
// expected-error@-1{{expansion of macro 'myWrapper()' did not produce a non-observing accessor (such as 'get') as expected}}
}
@ArbitraryMembers
struct OtherTestStruct {
}
// CHECK: MACRO_DECL
// CHECK-NOT: UnknownCode
// CHECK-PRINT-DAG: macro macroWithBuilderArgs(@Builder _: () -> Void)