[swift-evolution] Infer types of default function parameters
Jean-Daniel
mailing at xenonium.com
Sat Mar 11 02:57:02 CST 2017
-1
It would be inconsistent to allow it for deterministic literals (String) and not for non deterministic literal (int which can be either a Int, Uint, Float, …)
> Le 10 mars 2017 à 22:40, Kilian Koeltzsch via swift-evolution <swift-evolution at swift.org> a écrit :
>
> Hi all,
>
> I sent the message below to swift-users@ ~a day ago, but this might be a better place to ask and gather some discussion. It is a rather minor suggestion and I'm just looking for some opinions.
>
> Declaring a function that has default parameters currently looks like this:
>
> func foo(bar: String = "baz") {
> print(bar)
> }
>
> Now I'm wondering if there would be any problems if it were possible to omit the type annotation for default params and let Swift's type inference handle that.
>
> func foo(bar = "baz") {
> print(bar)
> }
>
> It feels to be equivalent to omitting type annotations with variable declarations. Obviously more complex types would still require annotations being specified. Off the top of my head I can't think of any negative ramifications this might bring, be it in simple function/method declarations or protocol extensions and elsewhere.
> Any further input or examples for situations where this might cause issues would be much appreciated :)
>
> Cheers,
> Kilian
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170311/d68b2022/attachment.html>
More information about the swift-evolution
mailing list