I'm trying to update my code for the latest Nim, and I'm hitting a weird error:
228 except Exception as exc:
229 let name: string = exc.name
t_raptor_db.nim(229, 43) Error: type mismatch: got <cstring> but expected 'string'
I'm trying to compare with the name of the exception. Why am I unable to convert from "cstring" to "string"?Why am I unable to convert from "cstring" to "string"?
Because you're not really converting. You're passing a cstring (right hand size of =) to something you declared as string (left hand side).
Try the following: let name = exc.name.string
Same error. Here is what I had:
- if exc.name == expected:
+ let name: string = exc.name.string
+ if name.startsWith(expected):
See? When I was comparing cstring to string, it was working, but now I need to test only the start (because the name changed from AssertionError to AssertionDefect). So now I'm wondering how the comparison worked if I am unable to type-convert.Btw, I'm at the bleeding edge:
commit ec65bfae3ac20a6c3d13249bc1fc8413db2b3abb (HEAD -> devel, origin/devel, origin/HEAD)
Author: Miran <[email protected]>
Date: Wed Jul 22 05:57:40 2020
Change testing commands for some packages (#15041)
So I'd understand if it's just a bug. But it's surprising to me.$(exc.name)
No need for the parentheses ... $ binds less tightly than .
A $ proc is defined for cstrings that returns a string.