You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@dynamicCallablestructS {
funcdynamicallyCall(withKeywordArgumentskvs:KeyValuePairs<String, String>) {}
}
vars = S()
s(testing:"testing")
That compiles. But now suppose our dynamically called method is supposed to mutate the struct. If we put `mutating` in front of `func`, we get a compile error: "cannot call value of non-function type 'S'".
I can work around this by making this a class instead of a struct. For example, this works:
Supporting for mutating func dynamicallyCall should be possible.
Similar support for mutating func callAsFunction is being implemented in #24299
There are still some bugs (namely with mutating func callAsFunction + IUO), but once done, the approach can be ported to dynamicallyCall.
I'm not sure whether this change to dynamicallyCall warrants any Swift Evolution discussion - I imagine it's noncontroversial.
Additional Detail from JIRA
md5: 0d961a467f1fb47f1346ba53df523c0f
Issue Description:
That compiles. But now suppose our dynamically called method is supposed to mutate the struct. If we put `mutating` in front of `func`, we get a compile error: "cannot call value of non-function type 'S'".
I can work around this by making this a class instead of a struct. For example, this works:
But if Flock is a struct, I can't find any way to do that.
The text was updated successfully, but these errors were encountered: