Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

[SoM] Consider Writing Weakly Typed Version of Functions That Return Protocol Lists #25

Open
stephen-hawley opened this issue Sep 5, 2019 · 1 comment
Assignees
Milestone

Comments

@stephen-hawley
Copy link
Contributor

This is a semantic impedance mismatch in play here.
In C# if I declare this method:

public T SomeFunc<T>() where T: IFaceA, IFaceB
{
}

It is up to the caller to decide what the type of T is.
In swift, if I write this method:

public func SomeFunc () -> ProtoA & ProtoB {
}

It is up to the callee to decide what the return type is.

In other words, we could write this method in swift:

public func SomeFunc (chooseWisely: Bool) -> ProtoA & ProtoB {
    if chooseWisely {
        return FirstChoice()
    } else {
        return SecondChoice()
    }
}

If it's mapped as a generic function in C#, this wouldn't work out right.
Likely the best thing to do is to instead make the function return type object and let the caller deal with it.

@stephen-hawley
Copy link
Contributor Author

I looked into this - it's...not easy. The problem is that in order to marshal something useful out of the ExistentialContainer you have to have a real C# type because we need a C# type to represent the type of the metadata. The problem is that in pulling out the actual object type, we have to ask questions like "how much memory do we need for the type?" and we don't have that.
In theory we could grab the SwiftMetatype out of the ExistentialContainer and map that to the type, but that map just doesn't exist and would be onerous to create. So, no?

@stephen-hawley stephen-hawley transferred this issue from another repository Oct 29, 2019
@chamons chamons added this to the Future milestone Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants