This fails to compile:
type
Range[T] = object
start, limit: T
proc fromTo[T: SomeOrdinal](a, b: T;): Range[T] =
result.start = a
result.limit = b
echo fromTo("a", "b")
But this compiles:
type
Range[T: SomeOrdinal] = object
start, limit: T
proc fromTo[T](a, b: T;): Range[T] =
result.start = a
result.limit = b
echo fromTo("a", "b")
And this crashes the compiler:
type
Range[T: SomeOrdinal] = object
start, limit: T
proc fromTo[T: SomeOrdinal](a, b: T;): Range[T] =
result.start = a
result.limit = b
echo fromTo("a", "b")
I'm using Nim version 0.17.0 on Windows. To me, only the first one makes sense. Am I missing something?
For example 1, string is not an Ordinal type.
From doc,
type
SomeOrdinal = int | int8 | int16 | int32 | int64 | bool | enum | uint8 | uint16 | uint32
For example 2, I'm not sure too but I never know that you can put type guard in type definition.
For example 3, I got crash too, Windows too