"Cannot assign" error for two values of the same type (and can not reproduce in isolation)

I have just run into a strange error:

Cannot assign value of type '[String : any ValueProtocol]' to type 'AttributeDictionary' (aka 'Dictionary<String, any ValueProtocol>')

in addition to a similar error:

Cannot convert value of type 'any ValueProtocol' to expected dictionary value type 'any AttributeValue' (aka 'any ValueProtocol')

The following function tries to demonstrate the error. The error is triggered with the following code at assignments three, a, b and d (all of the a, b, c, d are obvious because of the first error, added them just in case something else might be going on):

    typealias AliasedValue = ValueProtocol
    typealias AliasedDict = [String:ValueProtocol]
    
    public func f(maybeValue: Any?) {
        guard let value = maybeValue as? ValueProtocol else {
            return
        }
        let one: [String:ValueProtocol] = ["thing":value]
        let two: [String:AliasedValue] = ["thing":value]
        let three: AttributeDictionary = ["thing":value]
        let four: AliasedDict = ["thing":value]
        let a: AttributeDictionary = one
        let b: AttributeDictionary = two
        let c: AttributeDictionary = three
        let d: AttributeDictionary = four
    }

The declarations exist in a second package and their simplified version looks something like this:

public enum ValueType: String, Equatable, Codable {
    case nice
}

public protocol ValueProtocol {
    var valueType: ValueType { get }
}

public typealias AttributeKey = String
public typealias AttributeValue = ValueProtocol
public typealias AttributeDictionary = [AttributeKey:AttributeValue]

I tried to isolate the problem by creating a new package with two modules: one with declarations, another with the function. The error did not happen. Neither the error happens when I add the function at the top level of the package that my project depends on.

To make it more clear:

Let us have the following three packages:

  • Main: main package/project to be developed, requires Library
  • Library: a library package - a separate swift package containing functionality that Main uses
  • Isolated: a package that tries to isolate the error, has two modules:
    • IsolatedMain module: pretends to be 'Main', isolated function
    • IsolatedLib module: pretends to be Library, isolated definitions

The error does not occur when the (offensive?) function is present in the following packages/modules:

  • IsolatedLib
  • IsolatedMain (imports IsolatedLib)
  • Library

The error does occur only when used in Main that imports Library.

I do not know what is going on here, what I am doing wrong. It would be really helpful if I was at least able to isolate and reproduce the error in another context.

What I might be overlooking? What else should I try to identify the cause of this error?


Swift versions tried: XCode 14 (release) and swift-DEVELOPMENT-SNAPSHOT-2022-10-03

EDIT:

Additional observation: The following in the Main package:

    typealias AliasedDict5 = [AttributeKey:AttributeValue]
    typealias AliasedDict6 = [AttributeKey:AliasedValue]

and then its use:

        let five: AliasedDict5 = ["thing":value]
        let six: AliasedDict6 = ["thing":value]

... does cause error only on five not six. Note that the AliasedDict5 and AliasedDict6 are the same as AttributeDictionary, the only difference is that in AliasedDict6 AliasedValue is defined in the same module, where AttributeValue is defined in the library. Everything is public.