<FromGitter>
<plambert> I'm doing something like that, and I get that my Array(String) that I'm passing doesn't match...
<FromGitter>
<plambert> How can I make my array match the type that foo() is expecting?
<FromGitter>
<plambert> I've tried `.as(Array(String|Int32|Nil))` but it says it can't case Array(String) to Array(String|Int32|Nil). I can see not being able to go the other direction, but an Array(String) is 100% guaranteed to work as an Array(String | Int32 | Nil)… why can't the compiler see that?
<FromGitter>
<plambert> My example I gave (the def foo…) works in crystal eval… I'll try to reproduce my problem in something short…
<FromGitter>
<Blacksmoke16> prob want to do like
<FromGitter>
<Blacksmoke16> `foo ["hello"] of String | Int32 | Nil`
<FromGitter>
<Blacksmoke16> the problem ultimately is an `Array(String)` isnt the same as `Array(String | Int32 | Nil)` as like what would happen if you did like `x << 10; x << nil`
<FromGitter>
<plambert> So every caller has to explicitly cast to the exact type?
<FromGitter>
<plambert> I've narrowed it to this: `table=Array(Array(String | Int32 | Nil)).new; table << ["hello", 27]`
<FromGitter>
<Blacksmoke16> makes sense yea, the array you're trying to push doesnt allow nil
<FromGitter>
<plambert> But it is a valid Array(String | Int32 | Nil)
<FromGitter>
<Blacksmoke16> could make it an alias then would be able to do like `MyType["hello", 27]`
<FromGitter>
<plambert> It is an alias… I could try that. Still ugly for the caller.
<FromGitter>
<Blacksmoke16> but its not
<FromGitter>
<Blacksmoke16> are trying to push an array that doesnt allow `nil` into an array that requires arrays of `String | Int32 | Nil`
<FromGitter>
<plambert> That's a reproduction of what I'm seeing.
<FromGitter>
<plambert> I can't append the array to the existing array, even though I'm only accepting Array(TheTypes)... shouldn't the compiler be complaining that I'm passing Array(String|Int32) to #foo, which requires Array(String|Int32|Nil)?
<FromGitter>
<Blacksmoke16> ah so there's ivars involved
<FromGitter>
<Blacksmoke16> i think we're both right. compiler allows your array into the method, but is failing on the mutation of your ivar array
<FromGitter>
<plambert> I still feel like, for a *literal array*, this shouldn't happen. The compiler should be able to make its type match its only use case, since it's a literal. I totally get that passing a non-literal would not be permitted, since the compiler doesn't know what types might later be inserted. Or if the literal explicitly said it didn't allow Nil…
<FromGitter>
<Blacksmoke16> I'd read thru that link i posted earlier. Goes through this scenario. Tho my bad, i initialy forgot parameter restrictions are a bit less strict
<FromGitter>
<plambert> Thanks, I will!
<FromGitter>
<plambert> And thanks for all your help.
<FromGitter>
<plambert> I really love crystal. I've been programming since Perl 4, and it's definitely my favorite language.