-
Notifications
You must be signed in to change notification settings - Fork 558
RBS: Check signature parameters kind match the actual Ruby definition #8830
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
Conversation
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
rbs/MethodTypeToParserNode.cc
Outdated
return kind; | ||
} | ||
|
||
bool checkParameterKind(core::MutableContext ctx, const RBSDeclaration &declaration, const RBSArg &arg, |
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.
declaration
is unused.
rbs/MethodTypeToParserNode.cc
Outdated
|
||
bool checkParameterKind(core::MutableContext ctx, const RBSDeclaration &declaration, const RBSArg &arg, | ||
const parser::Node *methodArg) { | ||
auto error = false; |
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.
Can we rename this to something like kindMatches
? When I saw error
, I expected it hold some sort of error object, not a boolean.
rbs/MethodTypeToParserNode.cc
Outdated
|
||
if (error) { | ||
if (auto e = ctx.beginError(arg.loc, core::errors::Rewriter::RBSIncorrectParameterKind)) { | ||
e.setHeader("Argument kind mismatch for `{}`, expected `{}`, got `{}`", nodeName(methodArg).show(ctx.state), |
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.
The error message isn't super clear to me; it's not obvious that expected
is the arg in the def
, and got
is the one in the sig
. Maybe something like:
error: Argument kind mismatch for
p
, method declarespositional
, but RBS sig declaresoptional positional
#: (^() -> void) -> void | ||
# ^^^^^^^^^^^ error: Argument kind mismatch for `blk`, expected `block`, got `positiona 8000 l` | ||
def sig_mismatch11(&blk); end | ||
|
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.
Could you add a test case where the mismatch is in one of the args to the block?
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
// TODO: fix block location in RBS parser | ||
loc.beginLoc = loc.beginLoc + 1; | ||
loc.endLoc = loc.endLoc + 2; |
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.
The location given by the RBS parser is incorrectly offset, I'll fix this upstream and remove this adjustment in a follow up.
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.
TODO: fix the location in the RBS parser Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
673db09
to
a2fff8f
Compare
Motivation
I found a few cases where the kind of parameter used in the RBS signature was not matching the actual kind expected.
For example, all these cases should error :
but they do not
Test plan
See included automated tests.