8000 Skip type checking forwarded argument if the method is undeclared by soutaro · Pull Request #1519 · soutaro/steep · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Skip type checking forwarded argument if the method is undeclared #1519

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
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3869,7 +3869,11 @@ def type_check_args(method_name, args, constraints, errors)

case forward_arg_type
when nil
raise "Method context must have `forwarded_arg_type` if `...` node appears in it"
if context.method_context.method_type
raise "Method context must have `forwarded_arg_type` if `...` node appears in it"
else
# Skips type checking forwarded argument because the method type is not given
end
when true
# Skip type checking forwarded argument because the method is untyped function
else
Expand Down Expand Up @@ -4247,18 +4251,29 @@ def try_method_type(node, receiver_type:, method_name:, method_overload:, argume

case
when forwarded_args_node = args.forwarded_args_node
(_, block = method_context!.forward_arg_type) or raise
case forward_arg_type = method_context!.forward_arg_type
when nil
if method_context!.method_type
raise "Method context must have `forwarded_arg_type` if `...` node appears in it"
else
# Skips type checking forwarded argument because the method type is not given
end
when true
# Skip type checking because it's untyped function
else
_, block = forward_arg_type

method_block_type = method_type.block&.to_proc_type || AST::Builtin.nil_type
forwarded_block_type = block&.to_proc_type || AST::Builtin.nil_type
method_block_type = method_type.block&.to_proc_type || AST::Builtin.nil_type
forwarded_block_type = block&.to_proc_type || AST::Builtin.nil_type

if result = constr.no_subtyping?(sub_type: forwarded_block_type, super_type: method_block_type)
errors << Diagnostic::Ruby::IncompatibleArgumentForwarding.new(
method_name: method_name,
node: forwarded_args_node,
block_pair: [block, method_type.block],
result: result
)
if result = constr.no_subtyping?(sub_type: forwarded_block_type, super_type: method_block_type)
errors << Diagnostic::Ruby::IncompatibleArgumentForwarding.new(
method_name: method_name,
node: forwarded_args_node,
block_pair: [block, method_type.block],
result: result
)
end
end

when arg.compatible?
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/type_inference/send_args.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ module Steep

def pair: () -> [Parser::AST::Node, Interface::Function]?

def node_type: () -> AST::Types::t
%a{pure} def node_type: () -> AST::Types::t
end

class ForwardedArgs
Expand Down
35 changes: 35 additions & 0 deletions test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3498,4 +3498,39 @@ def bar(x)
YAML
)
end

def test_argument_forwarding__undeclared
run_type_check_test(
signatures: {
"a.rbs" => <<~RBS
class Foo
end
RBS
},
code: {
"a.rb" => <<~RUBY
class Foo
def foo(...)
1.to_s(...)
end
end
RUBY
},
expectations: <<~YAML
---
- file: a.rb
diagnostics:
- range:
start:
line: 2
character: 6
end:
line: 2
character: 9
severity: ERROR
message: Method `::Foo#foo` is not declared in RBS
code: Ruby::UndeclaredMethodDefinition
YAML
)
end
end
0