<FromGitter>
<Blacksmoke16> llvm-8 is quite old at this point
<FromGitter>
<skurhse> it does look like that issue
<FromGitter>
<skurhse> it's definitely a linkage editor issue
<FromGitter>
<skurhse> `collect2: error: ld returned 1 exit status`
<FromGitter>
<skurhse> i will do some research
Guest62 has joined #crystal-lang
Guest62 has quit [Quit: Client closed]
<FromGitter>
<erdnaxeli:cervoi.se> hi, why is this code compliing? https://carc.in/#/r/cl3e ⏎ `@debug` is declared as a `Bool`, but I am assigning it the value from a method that returns a `Bool?`
<FromGitter>
<Blacksmoke16> compiler seems to figure out it always returns a bool
<FromGitter>
<erdnaxeli:cervoi.se> hmm I am not sure I want the compiler to infer that ^^
<FromGitter>
<erdnaxeli:cervoi.se> but it avoid me to duplicate the method in this case
<FromGitter>
<skurhse> the return value can be null
<FromGitter>
<skurhse> if `value` is null
<FromGitter>
<erdnaxeli:cervoi.se> yep, but if `value` is of type `Bool`, the return type can only `Bool` (either the result of `==`, either `value` itself)
<FromGitter>
<erdnaxeli:cervoi.se> so the compiler is right, but it feels strange
<FromGitter>
<skurhse> is that it only adds the method signatures it needs per static analysis
<FromGitter>
<skurhse> so it's good to write good test cases
<FromGitter>
<skurhse> for instance with the right test case your code would return ⏎ `Error: instance variable '@debug' of Test must be Bool, not (Bool | Nil)`
<FromGitter>
<Blacksmoke16> do you have the code that produces it? because he has a method call for each case and it works fine
<FromGitter>
<erdnaxeli:cervoi.se> The thing is type restrictions are not strict in Crystal. I must admit I've never totally liked it, but I understand the point.
<FromGitter>
<Blacksmoke16> actually, interestingly enough if you do `read_bool(@debug, nil, "DEBUG")` still seems to know its always a `Bool`
<FromGitter>
<Blacksmoke16> is because `read_bool` returns `Bool?` when your local var is typed as `Bool`, thats prob a bug. might be an issue for it somewhere
<FromGitter>
<jrei:matrix.org> IIRC the type annotations are checked near the end of the compilation process, after code generation?
<raz>
not sure i see the bug there. compiler would still complain if your method could actually return nil.
<FromGitter>
<Blacksmoke16> think that case just needs a better error. e.g. if you did `record Foo, test : Bool = (false || nil)` you'd get a proper trace and `Error: instance variable '@test' of Foo must be Bool, not (Bool | Nil)`
<FromGitter>
<skurhse> you definitely proved undefined behavior
<FromGitter>
<Blacksmoke16> versus a more generic `Error: type must be Bool, not (Bool | Nil)`
<FromGitter>
<skurhse> `(false || nil)` is always `nil`
<FromGitter>
<skurhse> so if value permutations are discrete
<FromGitter>
<skurhse> `type must be Nil`
<FromGitter>
<Blacksmoke16> the runtime value of it is always `nil`, but its type is `Bool?`
<FromGitter>
<Blacksmoke16> e.g. try `pp typeof((false || nil))` versus `pp (false || nil).class`
<FromGitter>
<Blacksmoke16> the former is the compile time type, while the latter is runtime type
<FromGitter>
<skurhse> yes it's a bug
<FromGitter>
<skurhse> compare to `a : Nil = nil unless false` which works as expected
<FromGitter>
<skurhse> they can be inferred as well
<raz>
compiler apparently not smart enough to realize that it always evaluates to Nil
<FromGitter>
<Blacksmoke16> :shrug: if i had to guess its all based on compile time type of the value, which in the case of `(false || nil)` is `Bool?` but passing `true` to `test` results in `pp typeof(x) # => Bool`
<FromGitter>
<Blacksmoke16> ill defer to someone else if thats true or not, but afaik that seems to be whats going on
<FromGitter>
<Blacksmoke16> like this introduces a union due to the runtime nature, which then fails the restriction since the type of `x` is now the union and not reduced to `Bool`
<FromGitter>
<Blacksmoke16> not saying this is how its expected to work, but it is how it does amt
<FromGitter>
<jfontan> I am trying to make a fixed size array of type T. I am able to create it with `StaticArray(T, 10)` but I want the size to be specified by a variable. So it fails. I believe it is a macro and needs a number there. I'm also not able to create it with `T[@capacity]`. Do you know how it can be done?
<FromGitter>
<Blacksmoke16> er what the reason it works like that is* i should say
<FromGitter>
<Blacksmoke16> idt you can, static array sizes have to be known at a compile time
<FromGitter>
<Blacksmoke16> because, you know, they're static
<FromGitter>
<Blacksmoke16> could use a const or env value maybe?
<FromGitter>
<jfontan> I may try using a normal array and pushing to it then
<FromGitter>
<Blacksmoke16> you can use the expected size when creating the array to avoid reallocations
<FromGitter>
<jfontan> gotcha
<FromGitter>
<Blacksmoke16> i.e. allocate once for `@capacity` size
<FromGitter>
<Blacksmoke16> @skurhse could maybe make a forum thread about why those two cases are different id you want
notzmv has quit [Ping timeout: 240 seconds]
<FromGitter>
<skurhse> +1
<FromGitter>
<skurhse> i'm going to do some rca
<FromGitter>
<skurhse> trying to get more acquainted with compiler theory