<FromGitter>
<acook> > got an example? ⏎ ⏎ @Blacksmoke16 It didn't make it into a commit, so unfortunately I don't have a copy of it. I experimented with replicating it just now but couldn't. I wonder if the property I was calling was nilable and I just assumed it shouldn't be?
<FromGitter>
<acook> Hmm. It's not. It was a File::Info object and I was calling info.type.
<FromGitter>
<acook> The compiler would say that type could be nil when info wasn't nil, but that's not possible.
<FromGitter>
<acook> As File::Info.type is a non-nillable property.
<FromGitter>
<Blacksmoke16> Mmk, hard to help without reproducible code
<FromGitter>
<Blacksmoke16> sure you werent doing like `File.info?()`?
<FromGitter>
<Blacksmoke16> what was the reasoning for switching to `#{}`?
<oprypin>
Blacksmoke16, uhhhh syntax highlighting and also to have regex literals where i dont need to double-escape
<FromGitter>
<Blacksmoke16> gotcha
<straight-shoota>
also delegate work to the crystal parser =)
<oprypin>
straight-shoota, now i need to write `job_id` 3 times :s
<straight-shoota>
if you add more param validations and stuff, you'll have to write it even more often
<oprypin>
jrei:matrix.org, i don't know but there are still sites that aren't APIs, u know :D
<FromGitter>
<acook> @Blacksmoke16 I got it to replicate! Like I get why the level of indirection confuses the type checker, it just caught me offguard. Here's an example: https://play.crystal-lang.org/#/r/afsu
<FromGitter>
<jrei:matrix.org> OpenAPI is Swagger docs
<oprypin>
i think i'll have to revert the string interpolation stuff
<straight-shoota>
y?
<FromGitter>
<acook> (It turns out the culprit wasn't the nested if so much as the indirection of the property)
<FromGitter>
<Blacksmoke16> @acook `c` is essentially defaulted to `nil` fwiw
<FromGitter>
<Blacksmoke16> so this makes sense i think
<FromGitter>
<jrei:matrix.org> oprypin: a use case is to have a route per file type. Why not, the casting could be done with a param converter so for me it lead to the same result
<FromGitter>
<Blacksmoke16> like lucky does?
<FromGitter>
<acook> @Blacksmoke16 Yes, but if c is nil, it's only because b is too, so the case will never get there. It's kinda why I set the local variables, so that it couldn't change in the meantime.
<FromGitter>
<Blacksmoke16> would the compiler know that tho?
<FromGitter>
<acook> It *could* know that, but the information I assume isn't passed along with the c variable since like you said it defaults to nil. It's much more expedient to assume that it could be a problem.
<oprypin>
straight-shoota, adding the regex is too weird. also the fact that the interpolation is deferred is a trick rather than something to be proud of
<FromGitter>
<acook> I'm not arguing that it *should*, mind you.
<FromGitter>
<Blacksmoke16> @oprypin:matrix.org symfony does it like `"/blog/{page<\d+>}"`
<FromGitter>
<Blacksmoke16> using `<>` to deliminate the regex if that helps at all
<straight-shoota>
you could also use type declarations
<straight-shoota>
`/foo/bar/#{param : Int32}`
<oprypin>
straight-shoota, what to do with `: Time`
<FromGitter>
<acook> Yeah if I don't set the local for `c = b.baz unless b` it works, since the property is non-nillable. It's introducing that extra local/unless that breaks the chain of type info.
<straight-shoota>
well, don't use it :/
<oprypin>
not being a web framework *and* being a compile-time thing, it's hard to add registration of converters
<straight-shoota>
primitive types could have default regexes associated
<straight-shoota>
and I suppose you could also use constants
<straight-shoota>
like `#{param : MyTimeFormat}`
<oprypin>
does a global registry work for these?
<FromGitter>
<acook> It can be unfortunate if you expect the value to change during the course of a method call, you would have to add some unintuitive extra nil checks.
<FromGitter>
<Blacksmoke16> as by default `.to_i` strips whitespace
richbridger has joined #crystal-lang
<FromGitter>
<Blacksmoke16> im unsure if it should be an error by default, or allow it by default and require the user to add a like `\d+` to make it more strict
<straight-shoota>
I'd expect that to be strict
<straight-shoota>
I don't really understand why String#to_i strips whitespace by default
<FromGitter>
<oprypin:matrix.org> same
<straight-shoota>
I guess in some contexts, it doesn't matter
<FromGitter>
<Blacksmoke16> @straight-shoota actually would prob need to be a specific `.new(value : String) : self` overload since its only those ones that have the args
<straight-shoota>
yes, that's what I meant with "string overload"
<FromGitter>
<Blacksmoke16> i can grab that, be helpful for me :P
<FromGitter>
<Blacksmoke16> 👍
<straight-shoota>
I'll probably be looking into rounding behaviour for the number conversion methods :D
<FromGitter>
<Blacksmoke16> like if you call `.to_f32` on a `Float64`? 😉
<straight-shoota>
yeah any conversion from a float to a smaller float or int is rounded
<FromGitter>
<Blacksmoke16> ofc in your case it wouldnt need to worry about the column annotation or anything
<FromGitter>
<justin0mcateer> OK. I am going to do it the manual/tedious way for now. I can try to write a macro that handles it later. It's a bit over my head at the moment.
<FromGitter>
<justin0mcateer> Thanks for the advice!
<FromGitter>
<oprypin:matrix.org> @justin0mcateer why don't you just apply JSON::Serializable to those structs?? you don't need to enumerate fields, it does it for you
<FromGitter>
<justin0mcateer> Yeah, I could do that. I just don't want to have to serialize to JSON, then turn around and deserialize back to a Hash and do that in both directions.
<FromGitter>
<Blacksmoke16> does ducktape handle converting a hash into json to pass to js?
<FromGitter>
<Blacksmoke16> because a crystal hash isnt a js object
<FromGitter>
<oprypin:matrix.org> yes like why does a js library require a Crystal Hash?
<FromGitter>
<erdnaxeli:cervoi.se> we need a Hash::Serializable maybe? 🤔
<FromGitter>
<Blacksmoke16> 👎
<FromGitter>
<oprypin:matrix.org> yes but.. yes
<FromGitter>
<Blacksmoke16> that would prob just make people use hashes more when thats usually a bad idea
<FromGitter>
<oprypin:matrix.org> well but if you disregard bad people it'd be a good thing to have
<FromGitter>
<erdnaxeli:cervoi.se> yeah that was not a serious idea ^^