-
-
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
Regression in {.borrow.}
for generic type with static size
#22646
Comments
!nim c type
Vec*[N : static[int], T: SomeNumber] = object
arr*: array[N, T]
Vec3*[T: SomeNumber] = Vec[3, T]
proc `[]=`*[N,T](v: var Vec[N,T]; ix:int; c:T): void {.inline.} = v.arr[ix] = c
proc `[]`*[N,T](v: Vec[N,T]; ix: int): T {.inline.} = v.arr[ix]
proc dot*[N,T](u,v: Vec[N,T]): T {. inline .} = discard
proc length*[N,T](v: Vec[N,T]): T = discard
proc cross*[T](v1,v2:Vec[3,T]): Vec[3,T] = discard
proc normalizeWorks*[T](v: Vec[3,T]): Vec[3,T] = discard ## <- Explicit size makes it work!
proc foo*[N,T](u, v: Vec[N,T]): Vec[N,T] = discard ## <- broken
proc normalize*[N,T](v: Vec[N,T]): Vec[N,T] = discard ## <- broken
type
Color* = distinct Vec3[float]
template borrowOps(typ: typedesc): untyped =
proc `[]=`*(v: var typ; ix: int; c: float): void {.borrow.}
proc `[]`*(v: typ; ix: int): float {.borrow.}
proc dot*(v, u: typ): float {.borrow.}
proc cross*(v, u: typ): typ {.borrow.}
proc length*(v: typ): float {.borrow.}
proc normalizeWorks*(v: typ): typ {.borrow.} ## Up to here everything works
proc foo*(u, v: typ): typ {.borrow.} ## Broken
proc normalize*(v: typ): typ {.borrow.} ## Broken
borrowOps(Color) |
@juancarlospaco (collaborator) devel 👍 |
Fixed on devel ?. 🤔 |
Does the git bisecting helper always use the latest HEAD? |
Yeah it does, maybe try compiling latest head on your local?, which platform?. |
Uh, see my Nim version above. That is the latest head. |
reverts nim-lang#22642, reopens nim-lang#22639, closes nim-lang#22646, refs nim-lang#22640, refs alaviss/union#51
Description
After updating today for the
sizeof
fix (thanks!) I notice a regression in{.borrow.}
. I have a distinct type based on theVec
ofglm
. Borrowing for them is not possible anymore. It was compiling just fine yesterday on commit c5495f4.However, only procedures that return a type with the static size not explicitly specified are affected. As long as either the static size
N
is given explicitly or the return type does not containN
it works fine:UPDATE: This also seems to affect other things. I'm struggling to reproduce it at the moment, but just trying to convert a
Vec3d
to aColor
usingColor(foo)
is broken too. Based on the error message I think the problem is the same. It seems like the compiler is confused about the type equality.Nim Version
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-09-05
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: eb91cf9
active boot switches: -d:release -d:danger
Current Output
Expected Output
Possible Solution
No response
Additional Information
#22069 seems related?
The text was updated successfully, but these errors were encountered: