-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{.borrow:.
.} not working with distinct generics
#14449
Comments
Yep, just noticed that too. |
Sorry for the newbie question, but is there a way to work around this, apart from re-declaring accessors for the |
Working around type bugs is not a newbie question but an art. I use though mutable parameters requires some tricks with casts to raw addresses: # workarounds https://github.com/nim-lang/Nim/issues/14440
# so ugly ...
func `+=`(a: var Distance, b: Distance) {.inline.}=
cast[var float64](a.addr) += b.float64
func `-=`(a: var Velocity, b: Velocity) {.inline.}=
cast[var float64](a.addr) -= b.float64
func `+=`(a: var ATime, b: ATime) {.inline.}=
cast[var float32](a.addr) += b.float32
template `<`(a, b: ATime): bool =
a.float32 < b.float32
template `*`(accel: Acceleration, dt: ATime): Velocity =
Velocity(accel.float64 * dt.float64)
template `*`(v: Velocity, dt: ATime): Distance =
Distance(v.float64 * dt.float64)
template `*`(k: float64, v: Velocity): Velocity =
Velocity(k * v.float64) |
Thanks, but unless I'm missing a subtler point, it seem like it's a different issue? |
Ah right it was #14440, my bad. I created many distinct issues at that time. |
Related: #6039 |
The following fails to compile
The text was updated successfully, but these errors were encountered: