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

Is it Safe to Remove nonisolated(unsafe) in RealmCollectionImpl.swift? #8715

Open
yuioo1748 opened this issue Nov 19, 2024 · 1 comment
Open

Comments

@yuioo1748
Copy link

How frequently does the bug occur?

Always

Description

截圖 2024-11-19 下午1 19 41

Sorry, I'm still a beginner. After removing nonisolated(unsafe), the code runs normally. Is this the correct approach, or is there a recommended solution?

I look forward to your response, thank you!

// `with(object, on: actor) { object, actor in ... }` hands the object over
// to the given actor and then invokes the callback within the actor.
#if compiler(<6)
@available(macOS 10.15, tvOS 13.0, iOS 13.0, watchOS 6.0, *)
@_unsafeInheritExecutor
internal func with<A: Actor, Value: ThreadConfined>(
    _ value: Value, on actor: A,
    _ block: @Sendable @escaping (isolated A, Value) async throws -> NotificationToken
) async rethrows -> NotificationToken {
    if value.realm == nil {
        fatalError("Change notifications are only supported for managed objects")
    }

    let tsr = ThreadSafeReference(to: value)
    let config = Unchecked(wrappedValue: value.realm!.rlmRealm.configurationSharingSchema())
    return try await actor.invoke { actor in
        if Task.isCancelled {
            return nil
        }
        let scheduler = RLMScheduler.actor(actor, invoke: actor.invoke, verify: actor.verifier())
        let realm = Realm(try! RLMRealm(configuration: config.wrappedValue, confinedTo: scheduler))
        guard let value = tsr.resolve(in: realm) else {
            return nil
        }
        // This is safe but 5.10's sendability checking can't prove it
        // nonisolated(unsafe) can't be applied to a let in guard so we need
        // a second variable
        nonisolated(unsafe) let v = value
        return try await block(actor, v)
    } ?? NotificationToken()
}

Stacktrace & log output

'nil' is not compatible with closure result type 'NotificationToken' (aka 'RLMNotificationToken')
Cannot find 'nonisolated' in scope
Cannot find 'unsafe' in scope
Consecutive statements on a line must be separated by ';'

Can you reproduce the bug?

Always

Reproduction Steps

Create a new Swift project and use CocoaPods to get the latest version of Realm (version 20.0.0).

Version

20.0.0

What Atlas Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

macOS Sonoma 14.5

Build environment

Xcode version: 15.2
Dependency manager and version: CocoaPods

Copy link

sync-by-unito bot commented Nov 19, 2024

➤ PM Bot commented:

Jira ticket: RCOCOA-2458

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant