dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
153 stars 43 forks source link

Failed to load Objective-C protocol #1672

Closed brianquinlan closed 2 days ago

brianquinlan commented 2 days ago

When I attempt to use the NSURLSessionWebSocketDelegate delegate, I get this runtime failure: "Failed to load Objective-C protocol: NSURLSessionWebSocketDelegate".

I'm almost certain that this is caused by the fact that the the protocol is not used. From Protocols:

The compiler creates a protocol object for each protocol declaration it encounters, but only if the protocol is also:

Adopted by a class, or Referred to somewhere in source code (using @protocol()) Protocols that are declared but not used (except for type checking as described below) aren’t represented by protocol objects at runtime.

Adopting a Protocol

I was able to fix the issue by adding @protocol(NSURLSessionWebSocketDelegate); to my Objective-C code.

Since you need to generate Objective-C code anyway, you probably want to add @protocol(<protocol name>) for every protocol that you generate bindings for.

liamappelbe commented 2 days ago

Looks like I can't just drop that in the global scope. The compiler only recognises that syntax if it's part of an expression. I'll make some dummy functions that return @protocol(...) instead.