Hello nimmers,
I have created a library for calculating crc's and encountered some strange behavior with const computations in the templates (note, rev16b and rev8b works as expected!). I made a minimal example for you guys:
revxbits.nim
func rev32b*(b: uint32): uint32 = 0'u32
api.nim
import revxbits
template crcBitwise*(data: string): uint32 =
const ri = static: 0xFF'u32.rev32b
#const ri = revxbits.rev32b(0xFF'u32) ## work!
0'u32
main.nim
import api
# api.nim(4, 30) Error: undeclared field: 'rev32b' for type system.uint32
# [type declared in /x/nim-1.6.4/lib/system/basic_types.nim(11, 3)]
echo "123456789".crcBitwise()
Is this a bug or a feature? 🤔Typical template dotexpr issue can probably be resolved by doing the following. The issue stems from a.b in a template not being a call so it does not force bind symbols.
const ri = static: rev32b(0xFF'u32)
the following also may work, do not recall if it will.
template crcBitwise*(data: string): uint32 =
mixin rev32b
const ri = static: 0xFF'u32.rev32b