Files
swift-mirror/test/SourceKit/Macros/diags.swift
Hamish Knight 5dd258f99f [Diags] Avoid emitting fix-its for generated code
Drop fix-its produced in generated buffers, such
as for macro expansions, as these aren't directly
actionable by the user.

rdar://108231633
2023-05-23 11:37:40 +01:00

35 lines
1.2 KiB
Swift

@freestanding(expression)
macro coerceToInt<T>(_: T) -> Int = #externalMacro(module: "MacroDefinition", type: "CoerceToIntMacro")
@freestanding(expression)
macro stringify<T>(_: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
@attached(peer)
macro Invalid() = #externalMacro(module: "MacroDefinition", type: "InvalidMacro")
func foo() {
let _ = #coerceToInt("a")
let _ = #coerceToInt("b")
let _ = #stringify(#coerceToInt("c"))
}
@Invalid
struct Bad {}
@attached(member, names: arbitrary)
public macro addMemberWithFixIt() = #externalMacro(module: "MacroDefinition", type: "AddMemberWithFixIt")
// Make sure we don't emit the fix-it for the member added by this macro.
@addMemberWithFixIt
struct S {}
// REQUIRES: swift_swift_parser
// RUN: %empty-directory(%t)
//##-- Prepare the macro plugin.
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/../../Macros/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
// RUN: %sourcekitd-test -req=diags %s -- -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser %s | %sed_clean > %t.response
// RUN: %diff -u %s.response %t.response