The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
alias PermissiveType = Array(String | Int32) | String
s : PermissiveType = "hello world" #works
ss : PermissiveType = ["hello", "world"] # must be (Array(Int32 | String) | String), not Array(String)
PermissiveType
is strictly more permissive than Array(String)
this cast should be possible - any possible value of that more restrictive type should satisfy the more permissive type.
@ryanprior:matrix.org What you are running into is that while one can logically look at an Array(String) and see that an Array(String | Int32) can store everything in it, type specifications are very specific, and your type specification is for two things, either an Array(String | Int32), or String, and what you are trying to assign is an Array(String), which is not either of those things.
ss : PermissiveType = Array(String | Int32).new + ["hello", "world"]
That will create an array with a type signature that matches what PermissiveType allows.
Array(String)
@didactic-drunk that complete functionality doesn't exist so far as I am aware, but all of the building blocks exist. Maybe it can be my macro-hacking project of the week to build it.
Right now I am picturing something such as simple as include CallTrace
, followed by an annotation on top of any method that one want's to build a call tracing stack for.
The actual call trace would be accessible at any time.
A
as one of the branches of the case since it cannot have an instantiation at runtime
when
value is a type as the compiler expands it to is_a?