Struct with constructor doesn't compile

This compiles fine in XCode, but produces the following compiler message in Fire/Android:

E: Member “Message.<.>_SiteContainer0!.<>p__Site0" is less visible than inlined method "init( aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)” it is used from

public struct Message {

    //  Construction and disposition
    init(_ aType: String, _ aSender: Any, _ aReceiver: Any? = nil, _ aData: Any? = nil) {
        self.data = aData
        self.receiver = aReceiver
        self.sender = aSender
        self.type = aType
    }

    //  Properties
    public var data: Any?
    public var receiver: Any?  //  Can be nil if message is broadcasted
    public var sender: Any?
    public var type: String
}

False alarm for now. The problem lies somewhere else.

Update

Actually, the problem is this:

public class MessageHub {

//  This compiles,...
public func post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?,  _ aData: Any?) {
}

//  ... this doesn't
public func post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any? = nil, _ aData: Any? = nil) {
}

}

The same thing happens with default param values in Message constructor from my initial post.

a complete test case/project that shows this would be appreciated.

Yeah, the default params problem in Fire was actually NetStandard, not Android. I have both projects in the same solution and sometimes it’s hard to say which is which, the debug log isn’t very informative about it. Definitely some room for improvement in the UI part of Fire.

However, thanks to that, I found another problem with struct constructors where XCode won’t let me compile with convenience init, while Fire demands exactly that. As far as I can tell this doesn’t happen with classes.

Test projects for both issues attached.
Params and init problem.zip (464.8 KB)

Update

The default param problem with Message constructor also happens if Message is a class instead of struct. But this:

public class Message {

    public init(_ aType: String, _ aSender: Any, _ aData: Any?) {
        self.data = aData
        self.sender = aSender
        self.type = aType
    }

    public convenience init(_ aType: String, _ aSender: Any) {
        self.init(aType, aSender, nil)
    }

    public var data: Any?
    public var sender: Any
    public var type: String
}

compiles fine in both, XCode and Fire.

Can you elaborate on this? the debug log should be very clearly show this, as would the jumo bar, for a multi-project solution.

                  -> Phase Generating Output started.
E:                   Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
E:                   Member "MessageHub.<post>__SiteContainer0!.<>p__Site0" is less visible than inlined method "func MessageHub!.post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "MessageHub.<post>__SiteContainer0!.<>p__Site0" is less visible than inlined method "func MessageHub!.post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "MessageHub.<post>__SiteContainer0!.<>p__Site0" is less visible than inlined method "func MessageHub!.post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "MessageHub.<post>__SiteContainer0!.<>p__Site0" is less visible than inlined method "func MessageHub!.post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "MessageHub.<post>__SiteContainer0!.<>p__Site0" is less visible than inlined method "func MessageHub!.post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "MessageHub.<post>__SiteContainer0!.<>p__Site0" is less visible than inlined method "func MessageHub!.post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "MessageHub.<post>__SiteContainer0!.<>p__Site0" is less visible than inlined method "func MessageHub!.post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                     (0,0): duplicate-error E589: Member "MessageHub.<post>__SiteContainer0!.<>p__Site0" is less visible than inlined method "func MessageHub!.post(_ aMessageType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from
                  <- Phase Generating Output finished, took 0.1404s.

ah, I see these are location-less. that;'d make em hard to pinpoint, but thats a compiler bug, nothing Fire can fix. I’ll make a note of this when logging.

    public init(_ aValue1: Any) {  //  Fails in Fire/Android
        self.init(aValue1, nil)
    }

this seems valid to me. if a actor calls a different ctor in the same class (not a parent) it just be marked as convenience. At least that’s what Swift’s rules for that say. I’d consider this a bug in Apple Swift, not ours.

Thanks, logged as bugs://82232 (for Member "Message.<.>__SiteContainer0!.<>p__Site0" is less visible than inlined method "init(_ aType: String, _ aSender: Any, _ aReceiver: Any?, _ aData: Any?)" it is used from)

Makes sense. I’ll do #if JAVA || CLR for now and once and once default params are fixed there won’t be any need for convenience init.

Actually, as I think about this more, maybe it doesn’t make sense for structs, since there is no inheritance, so maybe Ap[ple made this inconsistent with classes by design, and we just overlooked that detail. I’ll review.

Logged as bugs://82235: Swift compatibility: noconvenience initon structs.

bugs://82232 got closed with status fixed.