Join GitHub today
Memory error when checking if a variable is a string in concept #7092
Hello, the following code compiles and then fails to run:
type stringTest = concept x x is string let a: stringTest = "111"
It gives the error
type stringTest = concept x x is string let a: stringTest = "111" let b: stringTest = "01"
I get the message "out of memory". This is on Ubuntu 17.10 with Nim 17.3.
I feel like this should work, but I am still learning the language, and so am not sure why it wouldn't.
@okamsn stringTest is a concept, not a concrete type. You can't create an object of a concept type.
Alright, so if I was trying to make a type that has certain requirements, should I be using a concept?
I know that the following code does run and compile in the same setup.
type intTest = concept x x is int let a: intTest = 1 echo a
Is there some automatic conversion going on here, then?
In this context, the concept is just used to verity that the value or the right-hand side of the assignment conforms to the concept requirements. The variables will end up with the concrete type of that value (here, this is string or int). There shouldn't be a crash, so this is a genuine bug that must be investigated.