Skip to content

Revert "[CS] Make sure macro arguments go through coerceCallArguments" #80830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5577,18 +5577,6 @@ namespace {
E->setMacroRef(macroRef);
E->setType(expandedType);

auto fnType =
simplifyType(overload.adjustedOpenedType)->castTo<FunctionType>();

auto newArgs = coerceCallArguments(
E->getArgs(), fnType, macroRef, /*applyExpr=*/nullptr,
cs.getConstraintLocator(E, ConstraintLocator::ApplyArgument),
solution.getAppliedPropertyWrappers(E));
if (!newArgs)
return nullptr;

E->setArgs(newArgs);

// FIXME: Expansion should be lazy.
// i.e. 'ExpandMacroExpansionExprRequest' should be sinked into
// 'getRewritten()', and performed on-demand. Unfortunately that requires
Expand Down
22 changes: 0 additions & 22 deletions test/Macros/macro_expand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -667,28 +667,6 @@ func testLocalAccessorMacroWithAutoclosure() {
takesAutoclosure(1)
}

@propertyWrapper
struct SomePropertyWrapper<T> {
var wrappedValue: T
init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}
init(projectedValue: Self) {
self = projectedValue
}
var projectedValue: Self { self }
}

// Property wrappers on macros probably aren't all that useful, but make sure
// we don't crash.
@freestanding(expression)
macro hasPropertyWrapperParam(@SomePropertyWrapper x: Int) = #externalMacro(module: "MacroDefinition", type: "GenericToVoidMacro")

func testPropertyWrapperMacro() {
#hasPropertyWrapperParam(x: 0)
#hasPropertyWrapperParam($x: .init(wrappedValue: 0))
}

#if TEST_DIAGNOSTICS
@freestanding(expression)
macro missingMacro() = #externalMacro(module: "MacroDefinition", type: "BluhBlah")
Expand Down
58 changes: 0 additions & 58 deletions test/Macros/macro_misc_diags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,6 @@ public struct TrailingClosureMacro: ExpressionMacro {
}
}

public struct CallClosureMacro: ExpressionMacro {
public static func expansion(
of macro: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) -> ExprSyntax {
guard let argument = macro.trailingClosure else {
fatalError()
}
return "\(argument)()"
}
}

public struct AddFunctionThatCallsClosureMacro: PeerMacro {
public static func expansion(
of node: AttributeSyntax,
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
guard case .argumentList(let args) = node.arguments else {
fatalError()
}
let arg = args.first!
return ["func qux() { \(arg)() }"]
}
}

public struct MakeBinding : DeclarationMacro {
static public func expansion(
of node: some FreestandingMacroExpansionSyntax,
Expand Down Expand Up @@ -90,12 +64,6 @@ macro identity<T>(_ x: T) -> T = #externalMacro(module: "MacroPlugin", type: "Id
@freestanding(expression)
macro trailingClosure<T>(_ x: T) -> T = #externalMacro(module: "MacroPlugin", type: "TrailingClosureMacro")

@freestanding(expression)
macro takesNonEscapingClosure(_ x: () -> Void) = #externalMacro(module: "MacroPlugin", type: "CallClosureMacro")

@attached(peer, names: named(qux))
macro AddFunctionThatCallsClosure<T>(_ fn: () -> T) = #externalMacro(module: "MacroPlugin", type: "AddFunctionThatCallsClosureMacro")

@freestanding(declaration, names: named(x))
macro makeBinding<T>(_ x: T) = #externalMacro(module: "MacroPlugin", type: "MakeBinding")

Expand Down Expand Up @@ -192,29 +160,3 @@ class rdar138997009_Class {
}
}
}

// https://github.com/swiftlang/swift/issues/80561
class TestNonEscaping {
func foo() {}
func bar() {
_ = #takesNonEscapingClosure {
foo()
}
_ = {
_ = #takesNonEscapingClosure {
foo()
// CHECK-DIAG: @__swiftmacro_6Client0017Clientswift_yEEFcfMX[[@LINE-3]]{{.*}}takesNonEscapingClosurefMf_.swift:2:9: error: call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit
// CHECK-DIAG: Client.swift:[[@LINE-2]]:9: warning: call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit; this will be an error in a future Swift language mode
}
}

@AddFunctionThatCallsClosure({ foo() })
func baz() {}
}
func qux() {
@AddFunctionThatCallsClosure({ _ = { foo() } })
func baz() {}
// CHECK-DIAG: Client.swift:[[@LINE-2]]:42: warning: call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit; this will be an error in a future Swift language mode
// CHECK-DIAG: @__swiftmacro_6Client15TestNonEscapingC3quxyyF7baz_$l{{.*}}AddFunctionThatCallsClosurefMp_.swift:4:13: error: call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit
}
}