-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implement instVarAt:[put:] #152
Conversation
stderr: | ||
Traceback... | ||
... | ||
Index 2 not valid for array of length 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, not the most ideal error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually I think instance values are an array, so this seems reasonable enough to me. [I half expected them to be exposed as an Array
as methods are!]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't something like "instVarAt: index 2 out of range" be more user-friendly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but not worth the effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll leave that one up to you.
Another test could be with a superclass that has fields. |
Can you expand upon this? The fact that it compiled without the |
|
||
run = ( | ||
x := 5. | ||
(self instVarAt: 2) println. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideas for more tests:
- Getting a larger valid index (e.g. index 5 out of 7).
- Getting a negative index should fail(?) with appropriate error message.
- Zero index should fail(?) with appropriate error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right... but it's just too much not-very-useful effort to do this for every indexing operation in SOM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's up to you. I tend to test the edge cases, as I don't trust my ability to get it right first time ;)
That's not how safety in Rust works. You can package up arbitrary amounts of deadly |
status: success | ||
stdout: | ||
5 | ||
instance of inst_var_at_put |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My curiosity gets the better of me again.
This is unusual. So this is some kind of proxy? Is it transparent? Can I use arithmetic on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just normal SOM, it's nothing really to do with this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gathered it's language semantics, was just curious.
@smarr's idea for a superclass test is a good one. I'll add that. |
This doesn't match my understanding. If you include anything Rust considers unsafe in a function, Rust will force you to mark the expression or the containing function unsafe. So if it compiled without You could mark any function unsafe on the virtue that somewhere inside is an |
If this was true, everything in Rust would need to be |
I think we are agreeing in that aspect, but that's not what I'm questioning.
As I understand it, you've added a redundant I'm not saying that's wrong to do so, I've just never seen it done and I'm considering if there's utility in such an idiom. |
Test added in 89bc1de. |
The unsafe argument was resolved in a (friendly) external discussion. I think I buy the reasoning :P |
Unless @smarr has any further comments, I think this is OK to go in. |
Reflecting SOM-st/SOM#44, I've expanded the test in cf10c7a (it works the same on Java SOM and yksom). |
Please squash. |
As it so happens, yksom already respects this new facet of the SOM spec (SOM-st/SOM#44), so the test alone is sufficient.
Squashed. |
bors r+ |
Build succeeded: |
These are two relatively simple primitives, although while doing this, I realised that some existing functions should be explicitly marked as
unsafe
(54422e8).