A strange problem: function returning nil instead returns random numbers
realgenekim opened this issue · 4 comments
Hi, @gnl —
Keep up all the amazing work. Just ran into the strange problem... Here's a function without ghostwheel...
(defn should-return-nil
[x]
nil)
=> #'x.asin/should-return-nil
(should-return-nil "")
=> nil
(should-return-nil "")
=> nil
And here's the same function with ghostwheel — it returns seemingly random numbers. I'm wondering if I'm doing something wrong?
(>defn should-return-nil-gw
[x] [string? => int?]
nil)
=> [x.asin/should-return-nil-gw]
; this fails, as expected...
(should-return-nil-gw 12)
Syntax error (ExceptionInfo) compiling at (asin.clj:23:3).
Call to amazonreviews.asin/should-return-nil-gw did not conform to spec:
12 - failed: string? in: [0] at: [:args :x]
; this has surprising return value
(should-return-nil-gw "")
=> -6922
(should-return-nil-gw "")
=> 0
(should-return-nil-gw "")
=> -31855
- Shouldn't the return value fail the spec, as it is not nilable?
- Why is it returning seemingly random numbers?
Thank you!
Gene
Hey @realgenekim – feature not a bug. :) see the 5th point here about spec-based stub generation:
https://github.com/gnl/ghostwheel#introduction
Admittedly, it's not as well documented as it should be and probably shouldn't be on by default – will take care of that for the next release.
@gnl Thanks for the quick reply! (And sorry for my delayed response.)
When I read your explanation, I breathed a huge sigh of relief, because I thought I was doing something crazy-wrong. :)
Yes, this is a really neat feature! But I agree with you — perhaps this should be disabled by default, because of how jarring it is if you're not expecting it.
Thanks again!
👋 Hi. I'm posting this same comment to all issue threads to just give a quick heads up that the project, despite rumours and some evidence to the contrary, is not dead. It was hibernating for a little while and now nearing the long-awaited next release, which will fix some long-standing issues (and introduce some breaking changes to the config).
I'll be reviewing all open issues and PRs over the next couple of weeks, so stay tuned and thanks for the patience.
See also this Slack thread