Is it possible to prevent Swift from logging "warning: the Swift runtime was unable to demangle the type of field..." messages?

It's adding an incredible amount of noise to my Xcode console, to the point where it's difficult to debug anything. (For additional context: the culprit seems to be using environmentObject(...) in SwiftUI — for whatever reason it looks like SwiftUI is Mirroring into the object's properties?)

If you are getting that warning, then something is corrupt in your binary. SwiftUI relies on field type metadata to work. Are you trying to strip or disable reflection metadata in your build?

1 Like

Here's the exact error message I'm seeing in Xcode 13.2.1 (13C100):

warning: the Swift runtime was unable to demangle the type of field '$defaultActor'. the mangled type name is 'BD': TypeDecoder.h:1003: Node kind 189 "^" - unexpected kind. this field will show up as an empty tuple in Mirrors

My environment object looks like this:

actor SomeEnvironmentObject: ObservableObject {
    private var facadeFetchTask: Task<Facade, Never>?
    private var fetchTaskCallbacks: [ (Task<Facade?, Never>) -> Void ] = []


I was surprised that using the environmentObject() modifier seems to be to triggering this message, since it only accepts ObservableObject reference-type values, and in that situation I'd expect SwiftUI to tell one instance from another using ObjectIdentifier and observe changes by subscribing to objectWillChange, and thus not really need to inspect the type at all (assuming that's what's happening here.)

What OS are you running on? That is a new type mangling used by the concurrency features, and it's possible there's a bug where we emit it even when back-deploying to older OSes that don't have the concurrency runtime support in the OS Swift runtime.

Big Sur (macOS 11.5.2)

Yeah, might be a bug with the back-deployed runtime then. Just to double-check, does your project also have macOS 11 or earlier as its minimum deployment target?

Spot on — it's set to macOS 11 exactly.

(Am I right in thinking that there isn't any way to silence this message? Looking at the Swift source code it looks like message is only really disabled in Playgrounds.)

This is probably an extremely dirty hack (plus it relies on an implementation detail so use it at your own risk!) but if this is really bugging you then you can probably can set the _playgroundPrintHook variable (it’s a global) to an empty closure (like _playgroundPrintHook = { string in }) . This should prevent those missing reflection metadata warnings from showing up in the console from the runtime, as it will fool it into thinking that you’re running the code in a Playground.

Keep in mind that you will miss out on other missing reflection metadata warnings too if you add new code or something changes that causes those warnings to be triggered. So, try to remove it once you’ve finished debugging your code for other issues.

You're a life saver! Sticking that in the earliest-running part of my app did the trick. Thanks!

Hi, how to find issue ? I rename actor to final class and get better :))) but non actor :frowning: