Open stephencelis opened 1 year ago
@xedin Hopefully not too painful of a thing to support :smile:
Here is a somewhat simpler example:
struct Foo<A> {
func f<B>(_: B.Type = A.self) {}
}
do {
Foo<Int>().f()
}
@stephencelis I don't think we can support { $0 }
because we don't actually inject expressions into call site but use value of expression type instead, in order to form that value we need to make sure that it could be used to infer types for parameter which means that parameter type of (A) -> C
is opened into ($T_A) -> $T_C
and there are no types in the body to substituted for that.
Same with @AnthonyLatsis's example - = A.self
should be rejected by the compiler because the expression couldn't be used in expression context to infer B.Type
.
but use value of expression type instead
@xedin I am not sure I follow. Can we not infer B
by opening B.Type
and the type of A.self
and equating them?
@AnthonyLatsis types of default expressions are not opened because again the actual value expression is not used in expression context which means that A.Type
in this case acts as a archetype of generic parameter A
in regards to expression Foo<Int>().f()
and that's invalid, the compiler should have rejected _: B.Type = A.self
parameter declaration.
@stephencelis I can either close this as expected behavior or turn it into a feature request. Which do you prefer?
I think a feature request would be nice. It does feel like a lot of Swift's type checking is getting super nuanced these days, so capturing more naive expectations would probably be a good idea.
Ah, I forgot our examples exposed a bug where default arguments are not rejected. I will open a new issue for those then.
Description
There seem to be some edge cases around identity functions that cause problems for SE-0347.
Steps to reproduce
A simple example:
While it'd be nice for this to work, the limitation is somewhat understandable. Making things more explicit, gets the base method compiling:
But actual use leads to ambiguity if generics are unknown:
Expected behavior
I expect the above to compile.
Environment