<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hmm, I don't know. It also works with other nominal types. For example:<div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">struct S {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">&nbsp; var x: Int</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">&nbsp; var y: Int</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">}</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">let s1 = S(x: 0, y: 1)</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">let s2 = S(x: 2, y: 3)</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">let arr = [s1, nil, s2]</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">print(type(of: arr)) <span class="Apple-tab-span" style="white-space:pre">                </span>// Array&lt;Optional&lt;S&gt;&gt;</font></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 24.03.2017 um 11:30 schrieb Rien &lt;<a href="mailto:Rien@Balancingrock.nl" class="">Rien@Balancingrock.nl</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><div class="">Btw, I just looked it up and it seems to me that inference only works for literals. Which probably means that tuples are out.<br class=""><br class="">Regards,<br class="">Rien<br class=""><br class="">Site: <a href="http://balancingrock.nl" class="">http://balancingrock.nl</a><br class="">Blog: <a href="http://swiftrien.blogspot.com" class="">http://swiftrien.blogspot.com</a><br class="">Github: <a href="http://github.com/Balancingrock" class="">http://github.com/Balancingrock</a><br class="">Project: <a href="http://swiftfire.nl" class="">http://swiftfire.nl</a><br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 24 Mar 2017, at 11:22, Rien via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""><br class="">IMO this is a boundary problem.<br class="">How far do you want to go in letting the compiler deduce the actual type?<br class="">It is possible to make very elaborate constructs that would basically default to a complex tuple/array/dictionary construct with only Any?’s in them. (well, the dict would require a Hashable too)<br class=""><br class="">Besides, the recent discussion on compile times illustrates another angle to this problem: if type inference is used extensively, compile times go to infinite…<br class=""><br class="">So while I do not know if this is a bug or not, I would recommend not to use it anyhow.<br class=""><br class="">Regards,<br class="">Rien<br class=""><br class="">Site: <a href="http://balancingrock.nl" class="">http://balancingrock.nl</a><br class="">Blog: <a href="http://swiftrien.blogspot.com" class="">http://swiftrien.blogspot.com</a><br class="">Github: <a href="http://github.com/Balancingrock" class="">http://github.com/Balancingrock</a><br class="">Project: <a href="http://swiftfire.nl" class="">http://swiftfire.nl</a><br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 24 Mar 2017, at 11:08, Toni Suter via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""><br class="">Hi,<br class=""><br class="">If I declare a variable and initialize it with an array literal whose elements are integer literals and nil literals,<br class="">the compiler will infer the type Array&lt;Optional&lt;Int&gt;&gt; for that variable:<br class=""><br class="">let arr = [1, nil, 3]<br class="">print(type(of: arr)) <span class="Apple-tab-span" style="white-space:pre">        </span>// Array&lt;Optional&lt;Int&gt;&gt;<br class=""><br class="">However, that only works with nominal types such as Int and String. If I do the same thing with an array of tuples,<br class="">I get a compile error:<br class=""><br class="">let arr = [(1, false), nil, (3, true)]<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// error: type of expression is ambiguous without more context<br class="">print(type(of: arr))<br class=""><br class="">Why can't the compiler infer the type Array&lt;Optional&lt;(Int, Bool)&gt;&gt; in this example? Is there a reason for this or is it a bug?<br class=""><br class="">Thanks and best regards,<br class="">Toni<br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>