You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-14229 [AutoDiff] conformance of synthesized TangentVector doesn't work
Issue Description:
Here is an example where declaring a conformance of a synthesized TangentVector to a protocol doesn't actually do anything:
import Foundation
import _Differentiation
publicprotocolP{}structS:Differentiable{vara:Float=23}// conformance to P works fine with SextensionS:P{}func asdf(p:P)->S{return p as!S}// conformance to P doesn't work with S.TangentVector ("Cast from 'P' to unrelated type 'S.TangentVector' always fails")extensionS.TangentVector:P{}func asdf2(p:P)->S.TangentVector{return p as!S.TangentVector}letinstance=S()lettangent=S.TangentVector(a:9)// conformance to P works fine with Sprint(asdf(p: instance))// conformance to P doesn't work with S.TangentVector, despite declaring that exact conformance above ("Argument type 'S.TangentVector' does not conform to expected type 'P'")print(asdf2(p: tangent))
Current workaround is to make a manual TangentVector (thanks @BradLarson):
import Foundation
import _Differentiation
protocolP{}structS:Differentiable{vara:Float=23structSTangent:Differentiable,AdditiveArithmetic{vara:Float}typealiasTangentVector=STangent}extensionS{mutatingfunc move(by offset:STangent){self.a += offset.a
}}extensionS:P{}func asdf(p:P)->S{return p as!S}extensionS.TangentVector:P{}func asdf2(p:P)->S.TangentVector{return p as!S.TangentVector}letinstance=S()lettangent=S.TangentVector(a:9)print(asdf(p: instance))print(asdf2(p: tangent))
The text was updated successfully, but these errors were encountered:
Environment
7/7/21 trunk snapshot
Additional Detail from JIRA
md5: f2964dbf441e2772fbb2a62aa7c4105e
duplicates:
Issue Description:
Here is an example where declaring a conformance of a synthesized TangentVector to a protocol doesn't actually do anything:
Current workaround is to make a manual TangentVector (thanks @BradLarson):
The text was updated successfully, but these errors were encountered: