Something changed in generics?

I had a working code very well last few years:

 func coordinatesOfCorner<C>(index: Int,
                                as: C.Type) -> [C]
    where C: SpaceCoordinateProtocol,
          Element == C.Axis
    {
        var result: [C] = []
        // ... counting result
        return result
    }

but after upgrading Xcode it doesn't work anymore and calling

let coordinates = GLOBAL_AXES.coordinatesOfCorner(index: index, 
                                                              as: Hyper.Coordinate.self)

returns error:
Generic parameter 'C' could not be inferred

Also function:

func coordinates<C>() -> [C]
    where C : SpaceCoordinateProtocol,
          C.Axis == Element
    {
        return self.map { axis in C(on: axis, position: axis.position) }
    }

worked pretty nice

let coordinates = axes.coordinates() as [Hyper.Coordinate]

returns similar error.

What changed in Swift and how to solve this problem?

It's not obvious to me what might be happening in the first example without seeing more details of the protocols and types involved, though someone else might have some ideas just from looking at your snippets. The best thing to do is to use feedback assistant to report the problem and attach a project or package that illustrates the problem ("this package builds correctly with Xcode X.Y, but not with Z.W").

Your second example looks likely to be a simple typo (as Hyper.Coordinate instead of as [Hyper.Coordinate]).

1 Like

I didn't make copy/paste, so typo [...] happened. What surprised me - something working before doesn't work anymore.

But maybe it's soemething on my side.

Was My fault. Some Generic class was defined Class<B,A> instead od Class <A,B>
And I don't know how to delete this post/

1 Like

No need to delete, it’ll get buried in time. Thanks for following-up.

1 Like