Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Can't use offsetOf on object that ends with an UncheckedArray #11320
Get an error trying to use offsetOf on an object that has an UncheckedArray as the
type Payload = object something: int vals: UncheckedArray[int] proc go() = echo "Offset " & $offsetOf(Payload, vals)
It looks like system.offsetOf is instantiating the object as a var, and that's what's causing it to fail.
I tried to see if the macros API is any better here as a workaround, and it seems like it is, but less that I though though. Here is an example.
import macros macro useoffsetof(arg: typed) = var typeImpl = arg.getTypeImpl # get rid of peskey typedesc while typeImpl.kind == nnkBracketEXpr and typeImpl.eqIdent("typeDesc"): typeImpl = typeImpl.getTypeImpl for identDefs in typeImpl: let sym = identDefs echo sym, ": ", getOffset(sym) type Payload = object something1, something2: int vals: UncheckedArray[int] useoffsetof(Payload)
The output is correct until you hit the