Type inference not working across module boundaries?

I can't seem to get type inference to work across module boundaries (or at least, across Swift Packages).

PackageA contains:

public struct Foo<T> {
    // Default T to Int.
    public init(type: T.Type = Int.self) { }

// Type inference says Foo<Int>, this compiles fine.
private let foo = Foo()

PackageB (which has a dependency on PackageA) contains:

import PackageA

// Type inference fails here?
/// Error: Generic parameter 'T' could not be inferred
/// Explicitly specify the generic arguments to fix this issue
let foo = Foo()

Is this a known limitation? Did I do something wrong?
Please let me know if you need to see the package manifests :slight_smile:

cc @xedin

I think this might have been fixed already, could you try with the recent 5.7 or main snapshot?

1 Like

Ok, I originally tried with Apple Swift version 5.7 (swiftlang- clang-1400.0.29.50). (Xcode 14 beta 5)

Will try with latest Xcode to see what happens, thanks!

Just got around to testing this again, works in Apple Swift version 5.7.1 (swiftlang- clang-1400.0.29.51) (Xcode 14.1 beta 2)

Thanks :+1:

1 Like