Skip to content

Commit

Permalink
Merge pull request #212 from soutaro/block-params-masgn
Browse files Browse the repository at this point in the history
Add UnsupportedSyntax error on masgn in block params
  • Loading branch information
soutaro authored Sep 16, 2020
2 parents 5193056 + 9e44d0d commit c130543
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,17 @@ def try_method_type(node, receiver_type:, method_type:, args:, arg_pairs:, block
if block_params && method_type.block
block_annotations = source.annotations(block: node, factory: checker.factory, current_module: current_namespace)
block_params_ = TypeInference::BlockParams.from_node(block_params, annotations: block_annotations)

unless block_params_
return [
Errors::UnsupportedSyntax.new(
node: block_params,
message: "Unsupported block params pattern, probably masgn?"
),
constr
]
end

pairs = block_params_.zip(method_type.block.type.params)

unless pairs
Expand Down
5 changes: 5 additions & 0 deletions lib/steep/type_inference/block_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def self.from_node(node, annotations:)

node.children.each do |arg|
var = arg.children.first

if var.is_a?(::AST::Node)
return
end

type = annotations.var_type(lvar: var.name)

case arg.type
Expand Down
20 changes: 20 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5453,4 +5453,24 @@ class << self
end
end
end

def test_block_param_masgn
with_checker(<<-RBS) do |checker|
class BlockParamTuple
def foo: () { ([Integer, String]) -> void } -> void
end
RBS
source = parse_ruby(<<-RUBY)
BlockParamTuple.new.foo do |(x, y)|
end
RUBY

with_standard_construction(checker, source) do |construction, typing|
construction.synthesize(source.node)

assert_equal 1, typing.errors.size
assert_instance_of Steep::Errors::UnsupportedSyntax, typing.errors[0]
end
end
end
end

0 comments on commit c130543

Please sign in to comment.