Uh oh!
There was an error while loading. Please reload this page.
Improve variable type name request - #14
Conversation
c150bb9 to
9109e88Compare9109e88 to
e3c5863Compare| M_RESPOND_TO_P = method(:respond_to?).unbind | ||
| M_METHOD = method(:method).unbind | ||
| M_OBJECT_ID = method(:object_id).unbind | ||
| M_NAME = Module.instance_method(:name) |
There was a problem hiding this comment.
I think we can use the same pattern as above.
| { name: name, | ||
| value: str, | ||
| type: type_name(obj), | ||
| type: type_name || type_name.to_s, |
There was a problem hiding this comment.
Instead of using this or, can't we always invoke to_s?
cfd91dc to
bf582fdCompare| { name: name, | ||
| value: str, | ||
| type: type_name(obj), | ||
| type: type_name.to_s, |
There was a problem hiding this comment.
type_name should already return a String so to_s may not be necessary?
There was a problem hiding this comment.
Yeah, everything appears to be working fine when I use just type_name. Does that make the to_s test unnecessary?
bf582fd to
d7908feCompare| end | ||
| end | ||
| class DAPOverwrittenToSMethod < ProtocolTestCase |
There was a problem hiding this comment.
Now that we don't call to_s anymore, do we still need this test?
d7908fe to
670f96aCompare
st0012
left a comment
There was a problem hiding this comment.
Yeah I think it's good to open a PR upstream now. Just a reminder that the PR description should be concise but mention:
- What's the behavioural difference with examples (e.g. parts of the response content)
- Why it's better
d59e3ca to
a136d09Comparea136d09 to
b83389aCompare
Description
ruby#790fixesthis issue. In this issue, the debugger raises the error:
I took a look at the repository this error was occurring in to figure out what was causing it. Essentially, this
ArgumentErroris coming from theself.namefunction having the parametervaluewhich is not provided whenklass.nameis called here, causing an exception.In ruby#790, if there is an exception when trying to get the class name, the variable's
typeis set to"<Error: #{e.message} (#{e.backtrace.first}>".My first commit adds three tests that test this functionality:
namemethod. The type should be an error message that begins with<Error: wrong number of arguments (given 0, expected 1).to_smethod. The type should be the same error as 1.namemethod and returnnilbecause thetype_namemethod checksklass.namefirst and without overriding the method to returnnil, the test does not triggerklass.to_sclassmethod. This was added in becauseM_CLASS.bind_call(obj)is used rather thanobj.classso adding a test to ensure the class name is being set appropriately and not raising an error is useful.I noticed that rather than catching an exception and setting the type to an error message, it would be better to use
M_NAME.bind_call(klass)to get the type name as this does not callklass.nameso there would be no error. This is an approach that is used by Tapioca here.In my second commit, I implemented this approach. I updated the tests from my first commit to reflect the new changes including removing the
to_stest as this method is no longer being used. You can see thetypeis nowFooinstead of an error message. This is more correct.