[swift-evolution] [Pitch] Remove type-inference for stored property
Lucas Neiva
lneiva at me.com
Wed Apr 12 07:50:04 CDT 2017
I think it’s worth thinking about, clarifying, and possibly documenting where inference happens and where it doesn’t.
As mentioned, there are limits to inference. Some of those limits are imposed by design, as in functions (check out F# to have your mind blown by how far type inference goes there).
- Type inference of function-local variable declarations is not the topic here. Everybody loves that :-D.
- For properties there are some levels to it, depending on the initial value:
- [inferred] Literals (String, Int, ...)
- [inferred] Constructor call, e.g. `Foo(a, b)`
- [inferred] Function call without generics, e.g. `someFunc()`
- [inferred] Function call with generics, e.g. `someArray.map(someGenericFunc)` (I believe this triggered the discussion, as it can cause performance issues)
- [NOT inferred] Function call with AMBIGUOUS types (impossible to infer)
- [NOT inferred] Closure, e.g. `{ /* do some stuff */ return /* some initial value */ }()`
- Computed properties, where currently the type is NOT inferred
- I’m unsure about how global properties are implemented, but I think the inference behaviour is the same there.
More information about the swift-evolution
mailing list