Skip to content

Conversation

@kubamracek
Copy link
Contributor

For Swift Testing's use of @section, but generally useful too, and function conversions like this are not problematic in terms of static initialization.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor

Given:

func x() {}

struct S {
  static func y() {}

  static let xPrime: @convention(c) () -> Void = x
  static let yPrime: @convention(c) () -> Void = y
}

The compiler rejects yPrime:

/swift/tmp/Sources/tmp/tmp.swift:7:50: error: a C function pointer can only be formed from a reference to a 'func' or a literal closure
5 | 
6 |   static let xPrime: @convention(c) () -> Void = x
7 |   static let yPrime: @convention(c) () -> Void = y
  |                                                  `- error: a C function pointer can only be formed from a reference to a 'func' or a literal closure
8 | }
9 | 

It is necessary to support @convention(c) closures here FBOFW.

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, LGTM

@kubamracek kubamracek enabled auto-merge November 10, 2025 20:06
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek kubamracek merged commit 75506a1 into swiftlang:main Nov 11, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants