Problem for existing code in Swift (Data, Operators)

I think it’s clear in the photo at below:

as you can see there is no support for Data so i can implement it. but i get lot of error for Ambiguous call. and also i realized operators are not supported exactly same as swift.

Well, what is Data? something you defined externally? What platform is this, and can you post the full project? thanx!

@mh in swift 3 NSData was changed to Data !
https://developer.apple.com/documentation/foundation/data

Full project:
LiteMQTT.zip (196.7 KB)

Nick,

indeed it was, but whether it’s called NSData or Data, it’s a Foundation class, and thus only available on Cocoa, not on Java ;).

If you want to write cross-platform code, i suggest using the Elements RTL library and looking at the Binary class, who is the cross-platform equivalent of Data.

Looking at the remaining issues in your project now.

@mh as i describe in the first post i can manage Data anyway it’s a object and i can create a class with name Data and internally use the Memory Stream. it’s clear for me. ok far away from this subject as you can see i have lot of error for operators. this is my main question not the object. and lot of Ambiguous! why? please download the project i sent and compile and see the all Ambiguous errors. on Operators and Contractors

@mh i know about the object that’s not exists in java. please take a looks to the syntax problem that all i want to know.

Most other errors also boil down to Cocoa specific APIs being used ion Java, such as GCD, specific string APIs, arc4random() (which is a C level Posix API), etc.

Remember that Silver is the Swift language, for different platforms. You are still targeting the Java platform and its APIs. Silver does not port Cocoa and the iOS/macOS SDKs to other platforms.

i did lng one issue for [weak self] throwing the compiler off:

78119: Swift Compatibility: [weak self] syntax for blocks does not compile

I’d be easier to see those if you could send me a project that shows just the specific syntax problems you are seeing. in a project with 89 errors, most of them “expected”, its hard to find the ones that are legitimate bugs; on a cursory glance, the one above was the only one that struck out as not being caused by unknown types, directly or indirectly.

e.g. ar these compiler bugs or bugs with the code base? hard to tell, given the operators you define on AppendableData themselves fail to compile due to calls to Cocoa specific APIs:

packet.variableHeader += nextMessageId() // E64 Type mismatch, cannot find operator to evaluate "AppendableData" + "UInt16"
packet.payload += topic // E62 Type mismatch, cannot assign "String!" to "AppendableData"
1 Like

@mh again. i know about the platform and i know about the language. i just want to start make this file compatible for Silver. OK. i hope we get out from the platform problem. i talking about SYNTAX problem.

  1. Why operators get error?
  2. Why constructors get same error (Ambiguous call)

Perfect. so if i fix the error i get success to compile this library.
Nice. it was my base question. i wasn’t sure if i fix it and again see the same error after some days.

Thanks.

Well, i don’t know. the errors might persist, and then we can have look and see if they are compiler bugs :wink:

the operators themselves failed to compile, so as far as the compiler knows when it gets to using them, they don’t exist :wink:

:grin: ok. i’ll try with one AppendableData if it’s worked i’ll continue :wink:

1 Like

@mh Again it’s me :grimacing: same problem.
MySilverPlayground.zip (180.8 KB)

Simple, simple simple :smile:

Thanks, logged as bugs://78121

1 Like

Good luck :wink:

turns out “by reference” operators are not something we currently support. I’ll make sure this will emit a cleaner error for the upcoming release (which is mostly locked down), and that well look at implementing proper support for these in the near future.

As a workaround, if tie declare a regular + operator, it will be applied/used for += as well. i’m not sure of that’s desirable.useful in your specific case here, but…

bugs://78121 got closed with status fixed.

1 Like

In swift you able to overload the operators. so by that you can easily change to your own procedure. Also you can test the same code in swift compiler and it’s will be work :wink: