Skip to content

Commit

Permalink
Update resolver for new forward argument syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Co-authored-by: Vinicius Stock <vinicius.stock@shopify.com>
  • Loading branch information
Morriar and vinistock committed Jun 3, 2021
1 parent e767753 commit 3b57e24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 5 additions & 4 deletions resolver/resolver.cc
Expand Up @@ -2542,12 +2542,13 @@ class ResolveSignaturesWalk {
auto methodInfo = method.data(ctx);

// Is this a signature for a method defined with argument forwarding syntax?
if (methodInfo->arguments().size() == 3) {
if (methodInfo->arguments().size() >= 3) {
// To match, the definition must have been desugared in exaclty 3 parameters named
// `<fwd-args>`, `<fwd-kwargs>` and `<fwd-block>`
auto l1 = getArgLocal(ctx, methodInfo->arguments()[0], mdef, 0, isOverloaded)->localVariable;
auto l2 = getArgLocal(ctx, methodInfo->arguments()[1], mdef, 1, isOverloaded)->localVariable;
auto l3 = getArgLocal(ctx, methodInfo->arguments()[2], mdef, 2, isOverloaded)->localVariable;
auto len = methodInfo->arguments().size();
auto l1 = getArgLocal(ctx, methodInfo->arguments()[len - 3], mdef, len - 3, isOverloaded)->localVariable;
auto l2 = getArgLocal(ctx, methodInfo->arguments()[len - 2], mdef, len - 2, isOverloaded)->localVariable;
auto l3 = getArgLocal(ctx, methodInfo->arguments()[len - 1], mdef, len - 1, isOverloaded)->localVariable;
if (l1._name == core::Names::fwdArgs() && l2._name == core::Names::fwdKwargs() &&
l3._name == core::Names::fwdBlock()) {
if (auto e = ctx.beginError(exprLoc, core::errors::Resolver::InvalidMethodSignature)) {
Expand Down
18 changes: 18 additions & 0 deletions test/testdata/resolver/forward_args.rb
Expand Up @@ -71,6 +71,24 @@ def foo_fwd3(...)
puts kargs # error: Method `kargs` does not exist on `Foo`
puts block # error: Method `block` does not exist on `Foo`
end

sig do
params(
a: T.untyped,
b: T::Hash[T.untyped, T.untyped],
c: T.untyped
).void
end # error: Unsupported `sig` for argument forwarding syntax
def foo_fwd4(a, b, c, ...)
puts a, b, c
end

def foo_fwd5(a, b, c, ...)
T.reveal_type(a) # error: Revealed type: `T.untyped`
T.reveal_type(b) # error: Revealed type: `T.untyped`
T.reveal_type(c) # error: Revealed type: `T.untyped`
d = T.unsafe(self).bar(a, b, c, ...)
end
end

Foo.new.foo_fwd
Expand Down

0 comments on commit 3b57e24

Please sign in to comment.