So today i was messing around with Generic types and I found something that I think would be considered "Undefined behavior". I thought I would just share it here in case anyone else gets the same idea.
type
Gen[val:static[auto]] = auto
true_t = Gen[true]
var a:true_t = "hello"
var b:true_t = 10
proc c(a:true_t):void =
echo a
c(a)
c(b)
the output here is understandable
Hint: system [Processing]
Hint: test [Processing]
Error: internal error: (filename: "semtypes.nim", line: 908)
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>
I would like to explain why I think this happens. I think that the error occurs because when declaring Gen[ whatever this may be] I actually turn true_t into two distinct types, and when executing the proc c it would probably expect the type string because that would be what the first actual definition of the proc does, or maybe because it is an ambiguous proc, though it doesn't really seem to catch onto that and just crashes.
It made me laugh a little so I thought I would share.
Thanks for reading
came up with a fix, so you cannot supply different types
type
same[T] = T
Gen[A:auto,val:static[same[A]]] = same[A]
Doesn't this do the same?
type
Gen_Stat[V:static[auto]] = V.type
true_t = Gen_Stat[true]
It would be really cool if I could limit the actual values you can supply to the variable
But they are limited already... Compilation breaks witha an appropriate message for smth like var a:true_t = 5. But maybe I misunderstood what you want.
No, that from your first post with the change from my post.
When you compile your last code, compiler says that the problem is with Var. You meant var (lowercased). You'd better not ignore compiler messages, can save your time.
Indentation matters too.
ah, yeah fixed the indentation and case mistakes, same problem though made an issue ticket on github
looks like there was some other problem. you are right that example now works
I assume i was using a 32 bit version of gcc or nim or i wasnt as up to date as i thought I will close the issue