<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=""><div class="">Seems like a bug, and moreover it seems like a regression from Swift 3.0. Mind filing a report at <a href="http://bugs.swift.org" class="">bugs.swift.org</a>?</div><div class=""><br class=""></div><div class="">Thanks!</div><div class="">Jordan</div><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 1, 2017, at 20:49, Howard Lovatt 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=""><div dir="ltr" class="">Hi All,<div class=""><br class=""></div><div class="">Anyone know what is going on here:</div><div class=""><br class=""></div><div class=""> //: Closure picks up static type not dynamic</div><div class=""> <br class=""> class MutableReference<T> {<br class=""> init() {<br class=""> guard type(of: self) != MutableReference.self else {<br class=""> fatalError("MutableReference is an abstract class; create a derrivative of MutableReference")<br class=""> }<br class=""> }<br class=""> var value: T {<br class=""> get {<br class=""> fatalError("Calculated property value getter should be overridden")<br class=""> }<br class=""> set {<br class=""> fatalError("Calculated property value setter should be overridden")<br class=""> }<br class=""> }<br class=""> }</div><div class=""> <br class=""> class DefaultMutableReference<T>: MutableReference<T> {<br class=""> private var _value: T<br class=""> override var value: T {<br class=""> get {<br class=""> return _value<br class=""> }<br class=""> set {<br class=""> _value = newValue<br class=""> }<br class=""> }<br class=""> init(_ value: T) {<br class=""> _value = value<br class=""> }<br class=""> }<br class=""><br class=""> let e: (MutableReference<[Int]>, Int) -> Void = { $0.value.append($1) }<br class=""> let dmr = DefaultMutableReference([2])<br class=""> dmr.value // [2]<br class=""> e(dmr, 2) // fatal error: Calculated property value getter should be overridden<br class=""> dmr.value // Expect [2, 2] <br class=""><p class="gmail-p1">If I change `e` to:</p> let e: (DefaultMutableReference<[Int]>, Int) -> Void = { $0.value.append($1) }<br class=""><p class="gmail-p1">It works fine.</p><p class="gmail-p1">IE the closure is using the static type of its first argument and not dynamically dispatching.</p><p class="gmail-p1">Am I doing something wrong? Is there a way round where I can still use the base class for `e`?</p><p class="gmail-p1"><br class=""></p><p class="gmail-p1">Thanks for any help in advance,</p><p class="gmail-p1">-- Howard.<br class=""></p>
</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>