ghostwheel icon indicating copy to clipboard operation
ghostwheel copied to clipboard

A strange problem: function returning nil instead returns random numbers

Open realgenekim opened this issue 6 years ago • 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

  1. Shouldn't the return value fail the spec, as it is not nilable?
  2. Why is it returning seemingly random numbers?

Thank you! Gene

realgenekim avatar May 18 '19 07:05 realgenekim

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 avatar May 20 '19 11:05 gnl

@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!

realgenekim avatar May 28 '19 03:05 realgenekim

👋 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

gnl avatar May 21 '20 01:05 gnl