mosquito-cr / mosquito

A background task runner for crystal applications supporting periodic (CRON) and manually queued jobs
MIT License
227 stars 24 forks source link

Unexpected argument when using `-Dno_number_autocast` #135

Closed jwoertink closed 5 months ago

jwoertink commented 5 months ago

This might be sort of an edge case, but we have to use the -Dno_number_autocast because without it, Crystal will freely interchange Floats and Ints in typed arguments. For us, this caused some REALLY bad issues.

When upgrading to Mosquito master branch to test things, everything fails. To recreate this, just update

https://github.com/mosquito-cr/mosquito/blob/0107dba08b18670832423f8e8d725b9b4f35db81/Makefile#L10-L11

and add in -Dno_number_autocast and you'll get this error when running make test

In test/mosquito/job_run/storage_test.cr:39:13

 39 | job_run.delete
              ^-----
Error: instantiating 'Mosquito::JobRun#delete()'

In src/mosquito/job_run.cr:65:5

 65 | def delete(in ttl = 0)
      ^-----
Error: instantiating 'delete(Int32)'

In src/mosquito/job_run.cr:66:43

 66 | Mosquito.backend.delete config_key, ttl
                                          ^--
Error: expected argument #2 to 'Mosquito::TestBackend.delete' to be Int64 or Time::Span, not Int32

Overloads are:
 - Mosquito::TestBackend.delete(key : String, in ttl : Int64 = 0)
 - Mosquito::TestBackend.delete(key : String, in ttl : Time::Span)
make: *** [Makefile:11: test] Error 1

Crystal version: 1.12.1 Mosquito Shard version: master branch

robacarp commented 5 months ago

I've never seen that flag before, thanks for bringing it up.

It seems like there's just a default argument in JobRun#delete that needs a default type? Or perhaps another overload to #delete that takes an int32, which is probably what I'd do. Jockying between bit-sizes of numerics is one area where I wish Crystal would do the ruby thing and "just work" instead of the C thing and "make me work" 🤪