New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.ArgumentException in memoizeWith #572
Comments
I think either option is more confusing than failing, because either way which generator "wins" is dependent on the order in which the generators are used (because the whole thing is lazy). So I would suggest going through methods explicitly instead of calling At least the error message can be improved though! |
Yeah I know the example code is bad, it was meant just as a minimal reproducible example that triggers the issue, i.e. that Common.memoizeWith doesn't take into account (at least not explicitly 😄) that |
I understand the example is very specific, but this problem is “known” to me in general. I understand you can fix it using one of the approaches you suggested, but my point the fix would make things potentially more confusing in many cases - at least when people are forced to use It’s in some sense similar to the aliasing problem with mutable data structures - if you write |
Closing after inactivity. Feel free to re-open if more questions. |
I recently ran into a
System.ArgumentException : An item with the same key has already been added.
inCommon.memoizeWith
with some custom generators/arbitraries. Below is minimal example test that triggers this (I know thatArb.generate
should be deferred here, and that indeed also avoids this issue, but it probably shouldn't crash with this code nonetheless). It seems thatCommon.memoizeWith
first concludes thatn
is not in thememo
, then callsf
, and then when it tries to addn
to thememo
this exception is raised becausen
is already in thememo
. This can be worked around by, after callingf
, either checking again ifn
is already in thememo
and only adding it if it's not, or simply removing and than (re-)adding it, Both seem to work, but I'm not sure which (if either) is the correct solution, so I'm making this just a report instead of a pull request for now.The text was updated successfully, but these errors were encountered: