-
Notifications
You must be signed in to change notification settings - Fork 567
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
Merged
+263
−38
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
046a749
Check RBS parameter kind is matching the actual Ruby definition
Morriar a68ab41
Fix existing tests
Morriar e42c4d5
Add more tests
Morriar f3f806b
Remove unused `declaration` parameter
Morriar 80196b2
Rename `error` local variable
Morriar cd3dd83
Rename `checkParameterKind` method
Morriar 42a7274
Reword error message
Morriar 92432f3
Adjust block location
Morriar a2fff8f
Document 3556 error
Morriar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
# let | ||
|
||
class Let | ||
#: (untyped) -> void | ||
#: (*untyped) -> void | ||
def foo=(*args); end | ||
|
||
#: -> untyped | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
# let | ||
|
||
class Let | ||
#: (untyped) -> void | ||
#: (*untyped) -> void | ||
def foo=(*args); end | ||
|
||
#: -> untyped | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,13 +40,51 @@ def parse_error4(p1, p2); end # error: The method `parse_error4` does not have a | |
def sig_mismatch1(p1, p2); end | ||
# ^^ error: Malformed `sig`. Type not specified for argument `p2` | ||
|
||
#: (foo: P1) -> void # error: Unknown argument name `foo` | ||
#: (foo: P1) -> void | ||
# ^^^ error: Argument kind mismatch for `p1`, method declares `positional`, but RBS signature declares `keyword` | ||
# ^^^ error: Unknown argument name `foo` | ||
def sig_mismatch2(p1); end | ||
# ^^ error: Malformed `sig`. Type not specified for argument `p1` | ||
|
||
#: (P1, P2, P3) -> void # error: RBS signature has more parameters than in the method definition | ||
def sig_mismatch3; end # error: The method `sig_mismatch3` does not have a `sig` | ||
|
||
#: (?Integer) -> void | ||
# ^^^^^^^ error: Argument kind mismatch for `p`, method declares `positional`, but RBS signature declares `optional positional` | ||
def sig_mismatch4(p); end | ||
|
||
#: (Integer) -> void | ||
# ^^^^^^^ error: Argument kind mismatch for `p`, method declares `optional positional`, but RBS signature declares `positional` | ||
def sig_mismatch5(p = 42); end | ||
|
||
#: (Integer) -> void | ||
# ^^^^^^^ error: Argument kind mismatch for `p`, method declares `keyword`, but RBS signature declares `positional` | ||
def sig_mismatch6(p:); end | ||
|
||
#: (Integer) -> void | ||
# ^^^^^^^ error: Argument kind mismatch for `p`, method declares `rest positional`, but RBS signature declares `positional` | ||
def sig_mismatch7(*p); end | ||
|
||
#: (?p: Integer) -> void | ||
# ^ error: Argument kind mismatch for `p`, method declares `keyword`, but RBS signature declares `optional keyword` | ||
def sig_mismatch8(p:); end | ||
|
||
#: (p: Integer) -> void | ||
# ^ error: Argument kind mismatch for `p`, method declares `optional keyword`, but RBS signature declares `keyword` | ||
def sig_mismatch9(p: 42); end | ||
|
||
#: (*Integer) -> void | ||
# ^^^^^^^ error: Argument kind mismatch for `p`, method declares `rest keyword`, but RBS signature declares `rest positional` | ||
def sig_mismatch10(**p); end | ||
|
||
#: (^() -> void) -> void | ||
# ^^^^^^^^^^^ error: Argument kind mismatch for `blk`, method declares `block`, but RBS signature declares `positional` | ||
def sig_mismatch11(&blk); end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
#: { -> void } -> void | ||
# ^^^^^^^^^^^ error: Argument kind mismatch for `p`, method declares `positional`, but RBS signature declares `block` | ||
def sig_mismatch12(p); end | ||
|
||
# Sigs | ||
|
||
# We do not create any sig if there is no RBS comment | ||
|
@@ -136,16 +174,16 @@ def method13(x) | |
end | ||
|
||
#: (?String x) -> void | ||
def method14(x) | ||
def method14(x = "") | ||
T.reveal_type(x) # error: Revealed type: `String` | ||
end | ||
|
||
#: (String x) -> void | ||
#: (?String x) -> void | ||
def method15(x = nil) # error: Argument does not have asserted type `String` | ||
T.reveal_type(x) # error: Revealed type: `T.nilable(String)` | ||
end | ||
|
||
#: (String ?x) -> void | ||
#: (?String? x) -> void | ||
def method16(x = nil) | ||
T.reveal_type(x) # error: Revealed type: `T.nilable(String)` | ||
end | ||
|
@@ -224,7 +262,7 @@ def bar; end # error: The method `bar` does not have a `sig` | |
end | ||
|
||
class FooProc | ||
#: (p: ^() -> Integer ) ?{ (Integer) [self: FooProc] -> String } -> void | ||
#: (?p: ^() -> Integer ) ?{ (Integer) [self: FooProc] -> String } -> void | ||
def initialize(p: -> { 42 }, &block) | ||
T.reveal_type(p) # error: Revealed type: `T.proc.returns(Integer)` | ||
T.reveal_type(block) # error: Revealed type: `T.nilable(T.proc.params(arg0: Integer).returns(String))` | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ruby/rbs#2456