!lymvtcwDJ7ZA9Npq:lix.systems

Lix Development

421 Members
(Technical) development of Lix, the package manager, a Nix implementation. Please be mindful of ongoing technical conversations in this channel.141 Servers

Load older messages


SenderMessageTime
14 Aug 2025
@emilazy:matrix.orgemily"fits into Nix integer → Nix integer, otherwise → error" would be acceptable for that too, but less interoperable with other JSON implementations and weird per the spec15:40:28
@emilazy:matrix.orgemily since adding a .0 isn't really meant to change a number by the specced JSON semantics 15:40:39
@emilazy:matrix.orgemily and indeed builtins.fromJSON "1.0" is 1 15:40:50
@emilazy:matrix.orgemily oh wait 1.0 also prints as 1 15:41:01
@emilazy:matrix.orgemily
nix-repl> builtins.isInt (builtins.fromJSON "1.0")
false

ok never mind :)

15:41:12
@emilazy:matrix.orgemilyanyway my point is just that we should pick one. the current behaviour is incoherent15:41:27
@aloisw:julia0815.dealoiswApparently that behaviour even changed, I remember it throwing or converting to float depending on the number of digits but now the float only happens when out of the unsigned range.16:27:10
@emilazy:matrix.orgemilyyes16:42:22
@emilazy:matrix.orgemilyit was changed when banning overflow in the Nix language16:42:25
@emilazy:matrix.orgemilyIMO that part of the change was a mistake16:42:31
@emilazy:matrix.orgemilywell, it would be just a difference of opinion if the negative values were handled consistently16:42:44
@jade_:matrix.orgjade_ i don't know what it should do 16:44:22
@jade_:matrix.orgjade_i chose to make it behave conservatively16:44:40
@emilazy:matrix.orgemily builtins.fromJSON "-9223372036854775809"'s behaviour is not conservative though 16:46:56
@emilazy:matrix.orgemilysee16:47:06
@emilazy:matrix.orgemilyJSON has only one numeric type and we certainly want everything that fits in a Nix integer to be represented as one (because Nixpkgs expects that). so the two options are optimistically coercing JSON literals that look like Nix integers into Nix integers and leaving the rest as floats, or coercing JSON literals that look like any kind of integer into Nix integers, leaving ones that are clearly floats as floats, and rejecting the rest. currently, we do neither16:48:52
@jade_:matrix.orgjade_correct, I would class that as "a bug"16:49:20
@emilazy:matrix.orgemily I think the former is what makes the most sense per JSON semantics and the general behaviour pointed at by the RFCs. the latter is defensible too. but picking one for positive values and another for negative values because of how nlohmann_json interacts with C++ numeric types not so much 16:49:22
@emilazy:matrix.orgemilyok. but I think it is hard to define these erroring semantics in a way that doesn't have weird edge cases wrt how JSON works16:50:09
@jade_:matrix.orgjade_ I think that getting a float in nix in general because it's nix is usually an undesired outcome 16:50:14
@emilazy:matrix.orgemilyfor instance, there are also JSOn literal floats that cannot be represented16:50:22
@jade_:matrix.orgjade_but alsoooo, often you want to passthru json16:50:26
@emilazy:matrix.orgemily* for instance, there are also JSON literal floats that cannot be represented16:50:26
@emilazy:matrix.orgemilyFWIW, the Nixpkgs integer parsing functions specifically reject the non-integer case, as I said16:51:02
@jade_:matrix.orgjade_so it is probably reasonable to try to just tolerate any numbers as losslessly as possible and eat the weird edge case that it's a float if it's too big16:51:05
@emilazy:matrix.orgemilyso returning floats does not make those behave spookily16:51:09
@emilazy:matrix.orgemily also, I don't think this should be a major consideration, but I suspect that making the negative case error out with nlohmann_json would be a pain 16:51:33
@emilazy:matrix.orgemilybecause it is already a float by the time you see it, because of being a value that does not fit into the integer types16:51:59
@emilazy:matrix.orgemilyI mean I guess you can compare the float but float precision issues may make that weird16:52:13
@emilazy:matrix.orgemilyand you have to determine whether it "could be" an integer16:52:20

Show newer messages


Back to Room ListRoom Version: 10