Skip to content
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

Silence warning in AXExtension #1435

Merged

Conversation

Eskils
Copy link
Contributor

@Eskils Eskils commented Aug 8, 2024

Aim

Due to a change implemented in Swift 5.9, Constrain implicit raw pointer conversion to bitwise-copyable values, a conversion to a raw pointer produces the warning: Forming an 'UnsafeRawPointer' to a variable of type 'T'; this is likely incorrect because 'T' may contain an object reference.

Since the affected function is only used with CGPoint and CGSize, the current implementation—that raises the warning—should be harmless.

Possible Solutions

The warning has been silenced by wrapping the code in withUnsafePointer(to:) {}.


Another possible solution could be to constrain T to the BitwiseCopyable protocol, new in Swift 6. This will make the compiler check if the type is safe to convert to an UnsafeRawPointer. In order to use this approach, the project needs to be migrated to Swift 6.

static func from<T: BitwiseCopyable>(value: T, type: AXValueType) -> AXValue? {
    var value = value
    return AXValueCreate(type, &value)
}

Considerations

  • It could be desirable to keep this warning as a way to remember to be careful with what types this utility-function is given. If so, feel free to close this PR.

@rxhanson
Copy link
Owner

rxhanson commented Aug 9, 2024

Thanks for the fix and the additional info; good to know about the BitwiseCopyable protocol.

@rxhanson rxhanson merged commit 20e73c2 into rxhanson:main Aug 9, 2024
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.

2 participants