From fc0a65386f47726c7ddb9f9576bb6170127b095b Mon Sep 17 00:00:00 2001 From: Pierre Jambet Date: Fri, 25 Mar 2022 15:35:19 -0400 Subject: [PATCH 1/3] Fix block with no param generation The issue occured when running the dsl command for an ActiveSupport::CurrentAttributes class with a method accepting a block with type: `T.proc.void`, resulting in the invalid `.params()` being generated. --- lib/tapioca/dsl/helpers/param_helper.rb | 3 ++- .../compilers/active_support_current_attributes_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/tapioca/dsl/helpers/param_helper.rb b/lib/tapioca/dsl/helpers/param_helper.rb index 8d79fd291..268192d1b 100644 --- a/lib/tapioca/dsl/helpers/param_helper.rb +++ b/lib/tapioca/dsl/helpers/param_helper.rb @@ -6,6 +6,7 @@ module Dsl module Helpers module ParamHelper extend T::Sig + include SignaturesHelper sig { params(name: String, type: String).returns(RBI::TypedParam) } def create_param(name, type:) @@ -39,7 +40,7 @@ def create_kw_rest_param(name, type:) sig { params(name: String, type: String).returns(RBI::TypedParam) } def create_block_param(name, type:) - create_typed_param(RBI::BlockParam.new(name), type) + create_typed_param(RBI::BlockParam.new(name), sanitize_signature_types(type)) end sig { params(param: RBI::Param, type: String).returns(RBI::TypedParam) } diff --git a/spec/tapioca/dsl/compilers/active_support_current_attributes_spec.rb b/spec/tapioca/dsl/compilers/active_support_current_attributes_spec.rb index 50bbdd57b..4c3f5fd5b 100644 --- a/spec/tapioca/dsl/compilers/active_support_current_attributes_spec.rb +++ b/spec/tapioca/dsl/compilers/active_support_current_attributes_spec.rb @@ -93,8 +93,8 @@ def helper # ... end - sig { params(user_id: Integer).void } - def authenticate(user_id) + sig { params(user_id: Integer, block: T.proc.void).void } + def authenticate(user_id, &block) # ... end end @@ -117,8 +117,8 @@ def account; end sig { params(value: T.untyped).returns(T.untyped) } def account=(value); end - sig { params(user_id: ::Integer).void } - def authenticate(user_id); end + sig { params(user_id: ::Integer, block: T.proc.void).void } + def authenticate(user_id, &block); end sig { returns(T.untyped) } def helper; end From a13a08b0bf1f6545a843371a4cd73b5265986568 Mon Sep 17 00:00:00 2001 From: Ufuk Kayserilioglu Date: Fri, 25 Mar 2022 21:59:31 +0200 Subject: [PATCH 2/3] Move signature type sanitization one level down --- lib/tapioca/dsl/helpers/param_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tapioca/dsl/helpers/param_helper.rb b/lib/tapioca/dsl/helpers/param_helper.rb index 268192d1b..b5da57adb 100644 --- a/lib/tapioca/dsl/helpers/param_helper.rb +++ b/lib/tapioca/dsl/helpers/param_helper.rb @@ -40,12 +40,12 @@ def create_kw_rest_param(name, type:) sig { params(name: String, type: String).returns(RBI::TypedParam) } def create_block_param(name, type:) - create_typed_param(RBI::BlockParam.new(name), sanitize_signature_types(type)) + create_typed_param(RBI::BlockParam.new(name), type) end sig { params(param: RBI::Param, type: String).returns(RBI::TypedParam) } def create_typed_param(param, type) - RBI::TypedParam.new(param: param, type: type) + RBI::TypedParam.new(param: param, type: sanitize_signature_types(type)) end end end From 5535e916e76659c69d131eb79529ca971ad95fe5 Mon Sep 17 00:00:00 2001 From: Ufuk Kayserilioglu Date: Sat, 26 Mar 2022 00:58:50 +0200 Subject: [PATCH 3/3] Add an explicit require for signatures helper --- lib/tapioca/dsl/helpers/param_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tapioca/dsl/helpers/param_helper.rb b/lib/tapioca/dsl/helpers/param_helper.rb index b5da57adb..e15e317ff 100644 --- a/lib/tapioca/dsl/helpers/param_helper.rb +++ b/lib/tapioca/dsl/helpers/param_helper.rb @@ -1,6 +1,8 @@ # typed: strict # frozen_string_literal: true +require "tapioca/helpers/signatures_helper" + module Tapioca module Dsl module Helpers