<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 24, 2017, at 3:08 AM, Toni Suter via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">If I declare a variable and initialize it with an array literal whose elements are integer literals and nil literals,</div><div class="">the compiler will infer the type Array<Optional<Int>> for that variable:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">let arr = [1, nil, 3]</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<Optional<Int>></font></div></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div class=""><div class="">However, that only works with nominal types such as Int and String. If I do the same thing with an array of tuples,</div><div class="">I get a compile error:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">let arr = [(1, false), nil, (3, true)]<span class="Apple-tab-span" style="white-space:pre">                </span>// error: type of expression is ambiguous without more context</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">print(type(of: arr))</font></div></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div class="">Why can't the compiler infer the type Array<Optional<(Int, Bool)>> in this example? Is there a reason for this or is it a bug?</div></div></div></div></blockquote><div><br class=""></div><div>Offhand it seems like we should be able to properly handle this. Can you open a bug report at <a href="http://bugs.swift.org" class="">bugs.swift.org</a>?</div><div><br class=""></div><div>Mark</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Thanks and best regards,</div><div class="">Toni</div><div class=""><br class=""></div></div>_______________________________________________<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=""></div></blockquote></div><br class=""></body></html>