Fire 8.3.92 (Beta) ERROR: E0: Internal error: An item with the same key has already been added

ah!!! Ok so it was the docs out-of-date. It’s ok now.

Not so much out of date, as just wrong (copy/paste bug from Oxygene docs ;). Fixed now, should be live in the next 5 mins.

@mh Regarding the Promise style in Swift in the Fire Beta 8.3.92 I see now three issues:

/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(53,3): error E121: Cannot instantiate interface type "Action2<Action1<AnyObject?>,Action1<AnyObject?>>!"

/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(57,11): error E43: No static member "All" on type "Promise"

/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(316,23): error E500: Parenthesis are required to call method observe(), cannot assign method group to "Action1<Promise>"

That are

convenience init(promiseClosure: ( resolve: (AnyObject?) -> (), reject: (AnyObject?) -> () ) -> ()) {
		self.init()
		
		let deferred = Deferred(promise: self)
            // the following will raise "Cannot instantiate interface type E121
		promiseClosure( resolve: deferred.resolve, reject: deferred.reject )
	}


class func all(promises: Array<Promise>) -> Promise {
            // this one will raise "No Such Static Member E43
		let all=All(promises: promises)
		return all
	}

and here

init(promises: Array<Promise>) {
		super.init()
		self.promiseCount = promises.count
		
		for promise in promises {
			let p = (promise as? Deferred == nil) ?
				promise :
				(promise as! Deferred).promise
			self.promises.append(p)
                    // "Parenthesis required for call E500
			p.statusObserver = observe
		}
		
	}

All these ones works in Xcode 7.2. I’m not sure if this is due to something missing in Swift 2.1 language support in Fire, btw do you think I could leverage all of them changing the code and keeping the same logic?

Thank you.

The last one seems valid? Without having the full code in front of me right now, how are observe and statusObserver defined?

Yes, it’s here: https://github.com/loretoparisi/swift-promise-example/blob/master/StaticLibrary/SharedProject/Promise.swift

Thanks!

@mh Regarding error E43:

/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(57,11): error E43: No static member "All" on type "Promise"

I have fixed it rewriting the class initializer call without explicit named parameter:

class func all(promises: Array<Promise>) -> Promise {
		return All(promises)
	} 

instead of return All(promises: promises)

This now compiles on Fire 9.3 beta, while in in Xcode 7.2 would give a compiler error:

"missing argument label:promise"

Regarding error E121,
I have tried to define a typealias for the closure:

typealias promiseClosure = ( resolve: (AnyObject?) -> (), reject: (AnyObject?) -> () ) -> ()

and the named the init parameter and called it:

convenience init(closure: promiseClosure ) {
    self.init()
    
    let deferred = Deferred(promise: self)
    closure( resolve: deferred.resolve, reject: deferred.reject )
}

This nows gives back the error:

/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(51,3): error E46: Unknown identifier "closure"

while it compiles and run as expected (going through the closures) in Xcode 7.2.

Hmm, that’s weird. if its defined as

class func all(promises: Array<Promise>) -> Promise {

there it should NOT need a prefix for the first parameter where calling, not in Xcode either. I’m a little bit confused with you mixing all and All in your snippets. Which one is it, or are there maybe both?

In any case, a func declared as ab one should be called as all([...]]) not as `all(promises: […]). to need a prefix for the first parametrer, you would need to explicitly state that in the decl:

class func all(promises promises: Array<Promise>) -> Promise {

or

class func all(# promises: Array<Promise>) -> Promise {

Note that for init(), the first name does get a prefix by default. but all is not an initializer, it’s a regular func. IOW,

convenience init(closure: promiseClosure ) {

does need to be called with prefix as WhateverClass(closure: ...), while all()`, as defined above does not.

Does this make sense?

@mh yes for the first issue E43 it was that one, but considering the call to

closure( resolve: deferred.resolve, reject: deferred.reject )

within

convenience  init(closure: promiseClosure)

why the closure parameter is not being recognized? I mean this should be correct for the compiler:

convenience init(closure: promiseClosure ) {
        self.init()
        let deferred = Deferred(promise: self)
        closure( resolve: deferred.resolve, reject: deferred.reject )
    }

like it does not recognized the symbol closure as a function / closure block.

I’m sorry, I’m just totally confused because there seem to be several different bugreports going on and overlapping, here, and i can cannot make heads or tails of this thread anymore :(. Can you post clean, simple and self-contained examples of what you think is broken — ideally in their one new dedicated threads? That’d be much appreciated.

So the problem is that you cannot call a closure passed in as parameter to init? let me try that… Yes, it seems that closures do not get/need prefixes for their parameters:

typealias PromiseClosure = ( resolve: AnyObject, reject: AnyObject) -> ()

class Foo {

	init(closure: PromiseClosure) {
		self.init()
		closure("", "") // this call works
		closure(resolve: "", reject: "") // this one does not: E46 Unknown identifier "closure"
	}

}

You’re correct; Apple Swift wants the second call. I’l log a bug for that. For any subsequent/new issues, even related to this same projects, could is till ask you to start a new/clean thread, to keep things easier to track?

thanx,
marc

Thanks, logged as bugs://74332: Silver: Closures need to require parameter names when called

bugs://74332 got closed with status nochangereq.

This got dropped in the swift language as part of :

Thanks for the update, a lot of changes in Swift 3 though!

Indeed.