From d43acf05cca49ada2fb0cfedb0549fdce2c3f0e4 Mon Sep 17 00:00:00 2001 From: Xenor Chang Date: Thu, 4 Jul 2024 11:39:35 +0800 Subject: [PATCH 1/4] fix: fix AASM compiler's global callback method signatures --- lib/tapioca/dsl/compilers/aasm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tapioca/dsl/compilers/aasm.rb b/lib/tapioca/dsl/compilers/aasm.rb index 23fcced5f..92dc2db5a 100644 --- a/lib/tapioca/dsl/compilers/aasm.rb +++ b/lib/tapioca/dsl/compilers/aasm.rb @@ -147,7 +147,7 @@ def decorate machine.create_method( method, parameters: [ - create_opt_param("symbol", type: "T.nilable(Symbol)", default: "nil"), + create_rest_param("callbacks", type: "T.untyped"), create_block_param("block", type: "T.nilable(T.proc.bind(#{constant_name}).void)"), ], ) From 3be095342b66593237b80e3c480ab8f4968133fd Mon Sep 17 00:00:00 2001 From: Xenor Chang Date: Thu, 4 Jul 2024 11:49:20 +0800 Subject: [PATCH 2/4] Fix tests --- spec/tapioca/dsl/compilers/aasm_spec.rb | 84 ++++++++++++------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/spec/tapioca/dsl/compilers/aasm_spec.rb b/spec/tapioca/dsl/compilers/aasm_spec.rb index 3afa37489..f87cd47ac 100644 --- a/spec/tapioca/dsl/compilers/aasm_spec.rb +++ b/spec/tapioca/dsl/compilers/aasm_spec.rb @@ -100,26 +100,26 @@ def aasm(*args, &block); end end class PrivateAASMMachine < AASM::Base - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_transactions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_transactions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_transitions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_transitions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def before_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def before_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def before_all_transactions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def before_all_transactions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def ensure_on_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def ensure_on_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def error_on_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def error_on_all_events(*callbacks, &block); end sig { params(name: T.untyped, options: T.untyped, block: T.proc.bind(PrivateAASMEvent).void).returns(T.untyped) } def event(name, options = nil, &block); end @@ -224,26 +224,26 @@ def aasm(*args, &block); end end class PrivateAASMMachine < AASM::Base - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_transactions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_transactions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_transitions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_transitions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def before_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def before_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def before_all_transactions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def before_all_transactions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def ensure_on_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def ensure_on_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def error_on_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def error_on_all_events(*callbacks, &block); end sig { params(name: T.untyped, options: T.untyped, block: T.proc.bind(PrivateAASMEvent).void).returns(T.untyped) } def event(name, options = nil, &block); end @@ -351,26 +351,26 @@ def aasm(*args, &block); end end class PrivateAASMMachine < AASM::Base - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_transactions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_transactions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def after_all_transitions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def after_all_transitions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def before_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def before_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def before_all_transactions(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def before_all_transactions(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def ensure_on_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def ensure_on_all_events(*callbacks, &block); end - sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } - def error_on_all_events(symbol = nil, &block); end + sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + def error_on_all_events(*callbacks, &block); end sig { params(name: T.untyped, options: T.untyped, block: T.proc.bind(PrivateAASMEvent).void).returns(T.untyped) } def event(name, options = nil, &block); end From cce6036468e841487b1dc2b81da1e0947fdbcc0e Mon Sep 17 00:00:00 2001 From: Xenor Chang Date: Sat, 6 Jul 2024 21:18:38 +0800 Subject: [PATCH 3/4] Update aasm.rb Co-authored-by: Ufuk Kayserilioglu --- lib/tapioca/dsl/compilers/aasm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tapioca/dsl/compilers/aasm.rb b/lib/tapioca/dsl/compilers/aasm.rb index 92dc2db5a..2938a7631 100644 --- a/lib/tapioca/dsl/compilers/aasm.rb +++ b/lib/tapioca/dsl/compilers/aasm.rb @@ -147,7 +147,7 @@ def decorate machine.create_method( method, parameters: [ - create_rest_param("callbacks", type: "T.untyped"), + create_rest_param("callbacks", type: "T.any(String, Symbol, T::Class[T.anything], Proc)"), create_block_param("block", type: "T.nilable(T.proc.bind(#{constant_name}).void)"), ], ) From 08610fbb857c969279240a188456a86b275934cd Mon Sep 17 00:00:00 2001 From: Xenor Chang Date: Mon, 8 Jul 2024 10:29:39 +0800 Subject: [PATCH 4/4] Fix tests --- spec/tapioca/dsl/compilers/aasm_spec.rb | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/spec/tapioca/dsl/compilers/aasm_spec.rb b/spec/tapioca/dsl/compilers/aasm_spec.rb index f87cd47ac..8159a8ea4 100644 --- a/spec/tapioca/dsl/compilers/aasm_spec.rb +++ b/spec/tapioca/dsl/compilers/aasm_spec.rb @@ -100,25 +100,25 @@ def aasm(*args, &block); end end class PrivateAASMMachine < AASM::Base - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_transactions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_transitions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def before_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def before_all_transactions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def ensure_on_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def error_on_all_events(*callbacks, &block); end sig { params(name: T.untyped, options: T.untyped, block: T.proc.bind(PrivateAASMEvent).void).returns(T.untyped) } @@ -224,25 +224,25 @@ def aasm(*args, &block); end end class PrivateAASMMachine < AASM::Base - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_transactions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_transitions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def before_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def before_all_transactions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def ensure_on_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def error_on_all_events(*callbacks, &block); end sig { params(name: T.untyped, options: T.untyped, block: T.proc.bind(PrivateAASMEvent).void).returns(T.untyped) } @@ -351,25 +351,25 @@ def aasm(*args, &block); end end class PrivateAASMMachine < AASM::Base - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_transactions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def after_all_transitions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def before_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def before_all_transactions(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def ensure_on_all_events(*callbacks, &block); end - sig { params(callbacks: T.untyped, block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } + sig { params(callbacks: T.any(String, Symbol, T::Class[T.anything], Proc), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) } def error_on_all_events(*callbacks, &block); end sig { params(name: T.untyped, options: T.untyped, block: T.proc.bind(PrivateAASMEvent).void).returns(T.untyped) }