<oprypin>
i don't know what exactly is happening there, is it a touch of a directory or symlink or something
<oprypin>
or is touch just broken?
<FromGitter>
<Sija> `File#touch` seems to work fine in other (win32) specs
<straight-shoota>
what confuses me is the error output
<straight-shoota>
it says "command failed: shards install" + normal output
<straight-shoota>
and that's a FailedCommand, so the exit code must be != 0
<straight-shoota>
but nothing written to stdout
<straight-shoota>
*no error
<oprypin>
straight-shoota: ah that's probably just because writing stderr is broken 😂
<straight-shoota>
ah
<straight-shoota>
that explains
<oprypin>
not stderr per se, it's just disabled because 2 streams at once is a deadlock
<oprypin>
it would seem very likely that touching a directory isn't a thing on Windows. but not sure if that's what's happening, and not even sure that we *are* dealing with a directory here
<FromGitter>
<Sija> oprypin: seems like it: `File.touch(Shards.install_path)`
<oprypin>
straight-shoota: anyway in the next 20hrs i don't plan to look into this one. if you do, first of course I'd suggest to try in CI if dropping just the part that touches the directory helps
<straight-shoota>
first thing is getting error output
<FromGitter>
<Sija> there r no specs for touching directory either
<FromGitter>
<Blacksmoke16> either a compiler error that i cant conditionally define an ivar, or the ivar not to be defined, or the ivar's value to be 123 like it should
<Andriamanitra>
yeah i guess a compiler error could make sense
<FromGitter>
<wyhaines> If anyone is interested, I am going to be noodling around with some Crystal code on Twitch tonight: https://twitch.tv/wyhaines
<FromGitter>
<watzon> I think I figured out part of the problem. You put a `{% print O %}` below this line (https://github.com/j8r/crystalizer/blob/master/src/crystalizer.cr#L8) you'll see that the type of `O` ends up being `(Bar | String)`, and since that union doesn't have any instance variables it doesn't return any.
<FromGitter>
<watzon> An easy fix is to monkey patch `Object` with the `each_ivar` method instead like this: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ and then in the serializer just call `each_ivar` directly on the object being passed in [https://gitter.im/crystal-lang/crystal?at=600a652097132e2480f77556]
<hightower2>
Hey do I see it right there's currently no OpenID Connect client lib for Crystal? Search for openid or oidc shards turns up nothing
<repo>
looks like it
fifr[m] has joined #crystal-lang
<frojnd>
Hi there.
<frojnd>
Can't find soluton how to make JSON::Any object an Array(String)
<frojnd>
Output of `JSON::Any` object is `["foo", "bar"]`
<FromGitter>
<Daniel-Worrall> `.as_a`
<FromGitter>
<Daniel-Worrall> will get you Array(JSON::Any)
<FromGitter>
<Daniel-Worrall> `.as_a.map(&.as_s)`
<FromGitter>
<Daniel-Worrall> Unless these are user provided JSON objects, you'll probably want to use deserialisation with a struct using JSON::Serializable
<FromGitter>
<Blacksmoke16> similar to `.as` but can use local vars
<FromGitter>
<jrei:matrix.org> that's the opposite of .as
<FromGitter>
<Blacksmoke16> how you figure? the example is the same as `number.as(Int32)` which is essentially what the implementation is doing
ua has joined #crystal-lang
<FromGitter>
<watzon> The problem is knowing the type to cast to. Since the type of `O` ends up being that union, we can't use it as a casting type.
<FromGitter>
<Blacksmoke16> where does the union come from? I assume its not from like `some_var : Int32 | Bool`?
<FromGitter>
<Blacksmoke16> `@some_var`*
<FromGitter>
<jrei:matrix.org> the method yields each ivar value
<FromGitter>
<jrei:matrix.org> It ends up being an union of all ivar types
<FromGitter>
<Blacksmoke16> ah
<FromGitter>
<Blacksmoke16> whats the reasoning for yielding them versus just macro for each ivar?
<FromGitter>
<jrei:matrix.org> It was working, I thought. I try using a macro instead
<FromGitter>
<jrei:matrix.org> this logic is shared in several places
<FromGitter>
<Blacksmoke16> fun fact not many people may know is you can access ivars of a type outside of the type generically via generics
<FromGitter>
<Blacksmoke16> may not know*
<FromGitter>
<Blacksmoke16> idk if that helps in this context, but i found it to be good to know
<FromGitter>
<jrei:matrix.org> I thought methods overload will dispatch to the correct method...
<FromGitter>
<watzon> So I figured out something that works, and this can definitely be refactored into a macro that will work for all of the serializers, but it might be a pain
<FromGitter>
<jrei:matrix.org> I mean, if a var has a type `Nested | String`, it will dispatch to either `serialize(v : String)` or `serialize(v : O) forall O`
<FromGitter>
<Blacksmoke16> :shrug: order might have some impact here
<FromGitter>
<Blacksmoke16> might get dispatched to the first one matching overload
<FromGitter>
<jrei:matrix.org> @watzon: right. I try to transform it to a macro, but I can't get iterating over ivars
<FromGitter>
<watzon> I think that unions like that will always get dispatched to to `serialize(v : O) forall O` because that's the closest matching overload.
<FromGitter>
<jrei:matrix.org> of course, I'm afraid this will cause lots of duplications :(
<FromGitter>
<jrei:matrix.org> but if there is no choice...
<FromGitter>
<watzon> It might be unavoidable. You could almost definitely refactor it into a macro, but the resulting macro might end up being more confusing in the end
<FromGitter>
<watzon> The main problem is that the serialization is done differently in each of the serializers
<FromGitter>
<jrei:matrix.org> right
<FromGitter>
<watzon> And in some cases, like the ByteFormat serializer, you don't even need the key
<FromGitter>
<watzon> It's just a weird case
<FromGitter>
<watzon> Granted this can always be refactored later
<FromGitter>
<Blacksmoke16> ah i missed teh string version of it works
<FromGitter>
<Blacksmoke16> could do like `{{pp O}} to see what all is making it to it
<FromGitter>
<Blacksmoke16> `{{pp O}}`
<FromGitter>
<Blacksmoke16> i dont see why that wouldnt work given `obj.@ns` would be the obj which should create an overload for that type, which should get used 🤔
<FromGitter>
<jrei:matrix.org> @Blacksmoke16 already tried to move it
<FromGitter>
<jrei:matrix.org> it was my first guess
<FromGitter>
<watzon> Fixed it, but we'll definitely need a macro for this
<FromGitter>
<watzon> Basically checks if the type is a union type , and if so generates a case statement that iterates over the types, then uses `.cast` to cast the type
<FromGitter>
<jrei:matrix.org> I have done a `de_unionize` method
<FromGitter>
<jrei:matrix.org> which iterates over the union
<FromGitter>
<watzon> Won't the return type of that method still be a union?
<FromGitter>
<jrei:matrix.org> not sure, no return types are set
<FromGitter>
<jrei:matrix.org> at least tests pass
<FromGitter>
<jrei:matrix.org> you may be right
<FromGitter>
<watzon> But within the method it's returning on the basis of a case statement, so to the compiler it's still going to be a union coming out
<FromGitter>
<watzon> Better to use a macro in cases like this
<FromGitter>
<jrei:matrix.org> the return type does not matter here
<FromGitter>
<jrei:matrix.org> because we are building to a String or IO
<FromGitter>
<watzon> I really like the idea of crystalizer, especially the ByteFormat part. I've been wanting a way to serialize Crystal objects to binary for a while.
<FromGitter>
<jrei:matrix.org> thanks! I did want something as dumb as possible, just a sequence of objects represented by bytes
<FromGitter>
<watzon> Seems to be exactly that. Basically just JSON or YAML without all the markup getting in the way.
<FromGitter>
<jrei:matrix.org> Exactly, it is not needed to pass key names when we control both ends
<FromGitter>
<Blacksmoke16> isnt that what like protobuf is?
<FromGitter>
<watzon> Protobuf adds some extra metadata to the objects does it
deavmi has joined #crystal-lang
<FromGitter>
<Blacksmoke16> :shrug:
<FromGitter>
<watzon> Generally with protocols like that they have a header in each packet that tells the receiver what kind of object to expect, it's length, etc.
<oprypin>
watzon, no protobuf relies on schema being already known to the receiver
<FromGitter>
<watzon> So it is just a raw byte representation of the object's properties?
<FromGitter>
<watzon> I just had a thought though. @jrei:matrix.org, the ByteFormat mode is order dependent isn't it? So if I were to serialize an object and then move a variable below another one in the class would that break things?
<FromGitter>
<watzon> I have no idea what order `TypeNode#instance_vars` returns variables actually
<FromGitter>
<jrei:matrix.org> @watzon: that's right, it is order dependent
<FromGitter>
<jrei:matrix.org> if you move the ivar, it will break. I planned to add annotations to explicitly define the order (but didn't yet)
<FromGitter>
<jrei:matrix.org> For my projects, if I modify any message, I just regenerate the JS bindings, recompile and redeploy everything
<FromGitter>
<jrei:matrix.org> @watzon I think you have confused with msgpack
<FromGitter>
<watzon> Might make more sense just to have a little extra metadata that acts as a key. That way ivars could change position, and new ones could even be added as long as they're not required to be initialized.
<FromGitter>
<watzon> That's possible
<FromGitter>
<jrei:matrix.org> Yes. Lots of annotations are also missing
<FromGitter>
<jrei:matrix.org> If you need those, I'll welcome any PR 😃
<FromGitter>
<watzon> I just might do some playing around
<FromGitter>
<jrei:matrix.org> I didn't feel the need because I use it for little projects, but I agree for large ones breaking the schema may be painful
<FromGitter>
<jrei:matrix.org> I use 0 annotations whatsoever for serialization (for now)
<FromGitter>
<jrei:matrix.org> Does Google use Crystal, at least :D?
<FromGitter>
<watzon> Hahahaha
deavmi has joined #crystal-lang
<FromGitter>
<watzon> Where does the default value for `#to_s` come from? I can't figure out how this `#<Foo:0x105d22e70>` is being generated.
<FromGitter>
<Blacksmoke16> you want to overload `to_s(io : IO) : Nil`
<FromGitter>
<Blacksmoke16> or `inspect(io : IO) : Nil`
<FromGitter>
<watzon> Ahh wait, it's coming from `Reference`
<FromGitter>
<watzon> I don't care about overloading, just trying to take a peek at how the method is getting the address
<FromGitter>
<watzon> So It's `Reference#object_id.to_s(16)` that's giving that hex value. Cool.
<FromGitter>
<Blacksmoke16> ah, 👍
<FromGitter>
<watzon> On an unrelated note, I wish we could do something like this: ⏎ ⏎ ```class Foo(T extends Bar) ⏎ end``` ⏎ ⏎ so that the compiler knows that `T` has to be a type that extends `Bar` [https://gitter.im/crystal-lang/crystal?at=600b4d61d8bdab473952b92e]
<FromGitter>
<Blacksmoke16> could prob use a macro for that check, ofc with not as clean syntax
<FromGitter>
<watzon> Yeah that's the problem, it would have to be in the initialize method
<FromGitter>
<watzon> I've done it, I just don't like it