<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=""><div class="">Whoops, should only look through one level of optionality. You get the gist.</div><div class=""><br class=""></div><div class="">~Robert Widmann</div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 31, 2016, at 2:31 PM, Robert Widmann <<a href="mailto:devteam.codafi@gmail.com" class="">devteam.codafi@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I taught <span style="font-family: Menlo; font-size: 11px;" class="">LinkedExprAnalyzer </span>about <span style="color: rgb(79, 129, 135); font-family: Menlo; font-size: 11px;" class="">ForceValueExpr</span></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">auto</span><span style="font-variant-ligatures: no-common-ligatures" class=""> FVE = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">dyn_cast</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ForceValueExpr</span><span style="font-variant-ligatures: no-common-ligatures" class="">>(expr)) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">LTI</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">collectedTypes</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">insert</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">CS</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">getType</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(FVE)-></span><span style="font-variant-ligatures: no-common-ligatures" class="">lookThroughAllAnyOptionalTypes</span><span style="font-variant-ligatures: no-common-ligatures;" class="">().</span><span style="font-variant-ligatures: no-common-ligatures" class="">getPointer</span><span style="font-variant-ligatures: no-common-ligatures;" class="">());</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">false</span><span style="font-variant-ligatures: no-common-ligatures" class="">, expr };</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div></div><div class=""><br class=""></div><div class="">This seems to get it - didn’t check whether this regresses things, but this seems to be the right fix at a high level.</div><div class=""><br class=""></div><div class="">~Robert Widmann</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 31, 2016, at 11:22 AM, Mark Lacey via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Dec 30, 2016, at 2:07 PM, Jacob Bandes-Storch via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">This is a pretty great bug:<span class="Apple-converted-space"> </span><a href="https://bugs.swift.org/browse/SR-3483" class="">https://bugs.swift.org/browse/SR-3483</a><div class=""><div class=""><br class=""></div><div class=""><div class=""><font face="monospace, monospace" class=""> let x: Double? = 1</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""> </font><span class="" style="font-family: monospace, monospace;">// error: ambiguous reference to member '+'</span></div><div class=""><font face="monospace, monospace" class=""> let sum = x! + x! + x!</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""> </font><span class="" style="font-family: monospace, monospace;">// error: value of optional type 'Double?' not unwrapped; did you mean to use '!' or '?'?</span></div><div class=""><font face="monospace, monospace" class=""> let sum: Double = x! + x! + x!</font></div></div><div class=""><br class=""></div><div class="">I've been poking around and I think the problem might be in LinkedExprAnalyzer.<span class="Apple-converted-space"> </span></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Yeah I think you’re onto something there. Just looking at the output of the constraint solver and where bindings are happening in matchTypes(), it looks like the constraint optimizer is trying to force the result type of both adds to ‘Double?’ rather than ‘Double’, so we only ever try to solve for that type.</div><div class=""><br class=""></div><div class="">I haven’t looked at the constraint optimizer code in a while, so I don’t have a lot of insight into the best fix, but it’s clearly the problematic piece here.</div><div class=""><br class=""></div><div class="">Mark</div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="">This class collects type info about elements in a chain of binary operators to speed up constraint solving. It does so in this case by grabbing the DeclRefExpr's type:<span class="Apple-converted-space"> </span><a href="https://github.com/apple/swift/tree/474096b9cbd6ff7ac998d7cea41d629512e25570#L230-L239" class="">https://github.com/apple/swift/tree/474096b9cbd6ff7ac998d7cea41d629512e25570#L230-L239</a></div><div class=""><br class=""></div><div class="">However, since this is an ASTWalker, (I think) it automatically traverses into the ForceValueExpr without remembering that the type it finds inside (from the DeclRefExpr) should have one level of optionality removed when added to the constraint system.</div><div class=""><br class=""></div><div class="">This theory sort of makes sense to me, but it doesn't explain why the simpler "<font face="monospace, monospace" class="">let sum = x! + x!</font>" typechecks correctly, because that goes through the same code path.</div><div class=""><br class=""></div><div class="">Am I correct that the LinkedExprAnalyzer probably needs to make sure it doesn't keep the Optional when adding the type of a ForceValueExpr? Why wouldn't this also cause problems for a single binop application?</div><div class=""><br class=""></div><div class="">Would it be more appropriate for LinkedExprAnalyzer to be an ASTVisitor (ExprVisitor) so that instead of just saying "yes, continue traversing downwards" (by returning {true, expr}), its ForceValueExpr case could recursively call visit() and then getAnyOptionalObjectType on the result?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Semi-eptly,</div><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class="">Jacob<br class=""></div></div></div></div></div></div></div>_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""></div></blockquote></div><br class=""></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-dev mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-dev@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">swift-dev@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>