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

I was compiling the following swift class:

I’m not able to find which is the duplicated symbol in the error log.

Following the stack trace:

mono /Applications/Fire.app/Contents/Resources/Mono/lib/mono/4.5/xbuild.exe /Users/admin/Documents/StaticLibrary/StaticLibrary.sln /nologo /target:Build /verbosity:normal /property:Configuration=Debug “/property:ElementsXbuildNougatSDKFolder=/Applications/Fire.app/Contents/Resources/Nougat SDKs” “/property:ElementsXbuildReferencePathsXMLFolder=/Applications/Fire.app/Contents/Resources/Reference Paths with Data Abstract Trial” /toolsversion:4.0

Build started 16/12/2015 17:06:00.


Project “/Users/admin/Documents/StaticLibrary/StaticLibrary.sln” (Build target(s)):
Target ValidateSolutionConfiguration:
Building solution configuration “Debug|AnyCPU”.
Target Build:
Project “/Users/admin/Documents/StaticLibrary/ClassLibrary2/ClassLibrary2.elements” (default target(s)):
Target CooperPreflight:
JDKRoot:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
JRERoot:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Target PrepareForBuild:
Configuration: Debug Platform: AnyCPU
Target ResolveAssemblyReferences:
Reference: android.jar
Reference: swift.jar
Reference: com.remobjects.elements.rtl.jar
Reference: sugar.jar
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target CoreCompile:
RemObjects Elements (RemObjects C# and Oxygene) Compiler for .NET, Cocoa and Java - Version 8.3.92.1901
Copyright 2003-2014 RemObjects Software, LLC. All rights reserved.
Source file: /Users/admin/Documents/StaticLibrary/SharedProject/Library.swift
Source file: /Users/admin/Documents/StaticLibrary/SharedProject/Promise.swift
Reference: /Users/admin/Library/Android/sdk/platforms/android-23/android.jar
Reference: /Applications/Fire.app/Contents/Resources/References/Elements/Cooper/swift.jar
Reference: /Applications/Fire.app/Contents/Resources/References/Elements/Cooper/com.remobjects.elements.rtl.jar
Reference: /Applications/Fire.app/Contents/Resources/References/CoreReferences/Cooper/Android/sugar.jar
Entering phase “Loading Source Files” (00:00:00.3199323)
Entering phase “Loading Resources” (00:00:00.0961202)
Entering phase “Resolving Namespaces” (00:00:00.0005674)
Entering phase “Resolving Types” (00:00:00.0112329)
: error E0: Internal error: An item with the same key has already been added.
Task “OxygeneCompiler” execution – FAILED
Done building target “CoreCompile” in project “/Users/admin/Documents/StaticLibrary/ClassLibrary2/ClassLibrary2.elements”.-- FAILED
Done building project “/Users/admin/Documents/StaticLibrary/ClassLibrary2/ClassLibrary2.elements”.-- FAILED
Task “MSBuild” execution – FAILED
Done building target “Build” in project “/Users/admin/Documents/StaticLibrary/StaticLibrary.sln”.-- FAILED
Done building project “/Users/admin/Documents/StaticLibrary/StaticLibrary.sln”.-- FAILED

Build FAILED.
Errors:

/Users/admin/Documents/StaticLibrary/StaticLibrary.sln (Build) ->
(Build target) ->
/Users/admin/Documents/StaticLibrary/ClassLibrary2/ClassLibrary2.elements (default targets) ->
/Applications/Fire.app/Contents/Resources/XbuildTargets/RemObjects Software/Oxygene/RemObjects.Oxygene.Cooper.Common.targets (CoreCompile target) ->

    : error E0: Internal error: An item with the same key has already been added.

     0 Warning(s)
     1 Error(s)

Time Elapsed 00:00:01.1863170

Thanks, logged as bugs://73929

I add the this works fine in Xcode 7.1.1 / swift 2.0, I’m able then to execute and run a Promise with defer like

  let promise = Promise { (resolve: (AnyObject?) -> (), reject: (AnyObject?) -> ()) -> () in
        
        print("Now resolve")
        resolve( 200 )
    }
    promise.then { (value) -> () in
        // Probably doing something important with this data now
        print( value )
        }
    .catch_ { (error) -> () in
        // Display error message, log errors
        }
        .finally { () -> () in
            // Close connections, do cleanup
    }

One of the problems seems to be related to the “extension” keyword (my guess) so I have uploaded a new Promise class that have all in the Promise and Defer classes here:

The doubt now is:
Does the semaphore here

func sync<T>(lock: AnyObject!, @noescape closure: () -> T) -> T {
    objc_sync_enter(lock)
    defer {
        objc_sync_exit(lock)
    }
    return closure()
}

will work in Fire?

Since I have those two there seems to be bridged from ObjC

/** 
 * Begin synchronizing on 'obj'.  
 * Allocates recursive pthread_mutex associated with 'obj' if needed.
 * 
 * @param obj The object to begin synchronizing on.
 * 
 * @return OBJC_SYNC_SUCCESS once lock is acquired.  
 */
@available(iOS 2.0, *)
public func objc_sync_enter(obj: AnyObject!) -> Int32

/** 
 * End synchronizing on 'obj'. 
 * 
 * @param obj The objet to end synchronizing on.
 * 
 * @return OBJC_SYNC_SUCCESS or OBJC_SYNC_NOT_OWNING_THREAD_ERROR
 */
@available(iOS 2.0, *)
public func objc_sync_exit(obj: AnyObject!) -> Int32

Yes, objc_sync* should work fine, compiles (no need to DEFINE those functions) and ends up generating correct code like :


func sync(lock, block)
  var tmpresult: Foundation.NSObject = nil;
  objc_sync_enter(lock)
  var t1 = objc_retainAutoreleasedReturnValueblock());
  objc_storeStrong(tmpresult, t1)
  objc_release(t1)
  return objc_autoreleaseReturnValue(tmpresult)
}

And yes, I did notice it has to do with the extension, I fixed the exception but there’s an underlying cause for this I need to solve before the issue is closed.

@ck Thanks! I have removed the extension and moved the class only instances. Now I’m into other errors, that seems to be language syntax (Swift 2.1) errors. Since they are of different kind (like No matching overload, Cannot instantiate interface type, Generic parameter cannot be resolved), I prefer to share the whole project.

Also it does not recognized the objc_sync_enter and objc_sync_exit (Unknown identifier error).
I have put the whole Fire project with the Shared Library and Android and iOS targets on github:

Note that the Promise.swift source compiles and run in Xcode as-it-is. To check this, I have added the Xcode test project as well in this repository.

So you will have

  • StaticLibrary: A Fire project with the Shared Library, Android and iOS targets
  • CrossTest: A Xcode (7.1.1 / Swift 2.1) project, to test the Swift library and the swift sources (for syntax and semantics checks, like for Promise.swift)

Cool. fwiw I fixed the original issues already. I’ll look at your full test case in a bit.

If you add:


	func sync<T>(lock: AnyObject!, @noescape closure: () -> T) -> T {
		objc_sync_enter(lock)
		defer {
			objc_sync_exit(lock)
		}
		return closure()
	}
	func sync(lock: AnyObject!, @noescape closure: () -> ())  {
		objc_sync_enter(lock)
		defer {
			objc_sync_exit(lock)
		}
		closure()
	}

(the second one) the sample mostly compiles, except for the missing api functions.

1 Like

@ck confirmed! Now I can see less errors (15):

 /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(34,16): error E287: Syntax error
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(34,16): error E1: closing bracket expected, got closing parenthesis
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(2,8): error E26: Unknown namespace "Promise" in uses list
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(19,17): error E44: No member "" on type "Promise"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(28,11): error E406: No overloaded method "then" with these parameters on type "Promise!", best matching overload is "then(_ then: Promise!.thenClosureNoReturn) -> Promise"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(76,32): error E44: No member "map" on type "Iterable<Promise>!"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(148,3): error E121: Cannot instantiate interface type "Action2<Action1<AnyObject?>!,Action1<AnyObject?>!>!"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(156,8): error E406: No overloaded method "then" with these parameters on type "Promise!", best matching overload is "then(_ then: Promise!.thenClosureNoReturn) -> Promise"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(211,3): error E46: Unknown identifier "objc_sync_enter"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(213,4): error E46: Unknown identifier "objc_sync_exit"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(218,3): error E46: Unknown identifier "objc_sync_enter"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(220,4): error E46: Unknown identifier "objc_sync_exit"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(233,32): error E44: No member "enumerate" on type "swift.Array<Promise!.thenClosure>!"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(268,9): error E105: Member "cat" on type "Promise" is a property but is used as a method
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(276,8): error E105: Member "fin" on type "Promise" is a property but is used as a method

that one is curious? Maybe a typo? That doesn’t show in your file.

sorry, let’s start with those 10, since the others dependes on import Promise failing module:

/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(76,32): error E44: No member "map" on type "Iterable<Promise>!"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(148,3): error E121: Cannot instantiate interface type "Action2<Action1<AnyObject?>!,Action1<AnyObject?>!>!"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(156,8): error E406: No overloaded method "then" with these parameters on type "Promise!", best matching overload is "then(_ then: Promise!.thenClosureNoReturn) -> Promise"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(211,3): error E46: Unknown identifier "objc_sync_enter"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(213,4): error E46: Unknown identifier "objc_sync_exit"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(218,3): error E46: Unknown identifier "objc_sync_enter"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(220,4): error E46: Unknown identifier "objc_sync_exit"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(233,32): error E44: No member "enumerate" on type "swift.Array<Promise!.thenClosure>!"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(268,9): error E105: Member "cat" on type "Promise" is a property but is used as a method
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(276,8): error E105: Member "fin" on type "Promise" is a property but is used as a method

         1 Warning(s)
         10 Error(s)

For these:

        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(211,3): error E46: Unknown identifier "objc_sync_enter"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(213,4): error E46: Unknown identifier "objc_sync_exit"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(218,3): error E46: Unknown identifier "objc_sync_enter"
        /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(220,4): error E46: Unknown identifier "objc_sync_exit"

you can just import Foundation; at the top.

@ck now I see why, I removed since I had a Unknown namespace “Foundation” in uses list. Any project settings to change?

You are targetting Cocoa right? Got Foundation in the “References”?

Right I was just sending you the project references:

Ah I didn’t realize you also wanted to do java too. That explains a lot.

Yes, absolutely! I’m building both the jar and the static a library from the shared lib.

That makes sense. But we’re heading in the realm of platform differences then. I’m going to log an issue for cross platform locking based on any object in Silver (bugs://73939). Can’t promise how this is going to look yet though.

Ok thanks. In the meanwhile, I confirm that if I disable the “classlibrary2” project (That is the Java one), now I can load Foundation then I get few errors:

  /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(78,32): error E44: No member "map" on type "RemObjects.Elements.System.INSFastEnumeration<Promise>!"
    /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(154,10): error E43: No static member "All" on type "Promise"
    /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(158,8): error E406: No overloaded method "then" with these parameters on type "Promise!", best matching overload is "then(_ then: Promise!.thenClosureNoReturn) -> Promise"
    /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(235,32): error E44: No member "enumerate" on type "Array<Promise!.thenClosure>!"
    /Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(270,9): error E399: No overloaded method "cat" with 1 parameter on type "Promise!"

     1 Warning(s)
     5 Error(s)

Regarding the Promise module, we talk about the semaphore primitives, but given this (supposed I’m not going to use that), any other way to achieve a similar (workaround) solution for both Cocoa / Java ?

Other question is, all the other errors, due to language support, like this

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

where All is a class member of the file.

Last question, any pragma to check the build target and exclude / include codes so having

import Foundation

only for the Cocoa Target?

Oke so first the locking. vnext will support:

	func sync(lock: AnyObject, @noescape closure: () -> ())  {
		__lock lock {
		  closure()
		}
	}

For all 3 platforms (no ties to the obscure objc calls)

1 Like