-
-
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
cstring and array[..., char] are treated the same by compiler for hashes.hash() #6350
Comments
Had to fight against that as well with regular string. You have various solutions with examples in my arraymancer library: Using "not char" - Source: proc shape[T: not char](s: openarray[T], parent_shape: seq[int] = @[]): seq[int] {.noSideEffect.}=
## Helper function to get the shape of nested arrays/sequences
result = parent_shape & s.len
when (T is seq|array):
result = shape(s[0], result)
proc shape(s: string|seq[char], parent_shape: seq[int] = @[]): seq[int] {.noSideEffect.}=
## Handle char / string
if parent_shape == @[]:
return @[1]
else: return parent_shape If you don't use generics, one proc with openarray and another with string (or cstring in your case) seem to work - Source: proc toTensor*(s:openarray, B: static[Backend]): auto {.noSideEffect.} =
## Convert an openarray to a Tensor
toTensorT(s,B)
proc toTensor*(s:string, B: static[Backend]): auto {.noSideEffect.} =
## Convert an openarray to a Tensor
##
## Handle string specifically (otherwise they are interpreted as openarray[char])
toTensorT(s,B) |
IMO, it is more foundation problem. Currently, array[,char] is implicitly castable to cstring and the right solution is to get rid of this implicit cast in the compiler. Nothing hash specific. For the same reason echo of array[, char] doesn't work |
@mratsim Thanks for the help. Appreciate the help from fellow Malagasy ;) and glad to see other guys from Dago using Nim. Actually, I am not aware of this @cooldome Indeed, this is not hash specific. I emphasize that this is pretty dangerous, as one could naively just cast to @dom96 has suggest in the chat that I could simply cast to |
|
Using this piece of code:
Whether I cast
x
to the array or not, I'm getting this error:I'm not sure if I'm missing something, but it seems simple, yet, I can't find a way to appease the compiler around this. It's a roadblocker.
The text was updated successfully, but these errors were encountered: