Problem for existing code in Swift (Data, Operators)


(Nick Msg) #1

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.

(marc hoffman) #2

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

(Nick Msg) #3

@mh in swift 3 NSData was changed to Data !

Full project: (196.7 KB)

(marc hoffman) #4


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.

(Nick Msg) #5

@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

(Nick Msg) #6

@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.

(marc hoffman) #7

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

Support for [weak self]?
(marc hoffman) #8

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"

(Nick Msg) #9

@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)

(Nick Msg) #10

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.


(marc hoffman) #11

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:

(Nick Msg) #12

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

(Nick Msg) #13

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

(Nick Msg) #14

Simple, simple simple :smile:

(RemObjects) #15

Thanks, logged as bugs://78121

(Nick Msg) #16

Good luck :wink:

(marc hoffman) #17

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…

(RemObjects) #18

bugs://78121 got closed with status fixed.

(Nick Msg) #19

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: