`strong_memoize_attr` with `override` break the static analysis job
Problem
The newly added strong_memoize_attr
breaks the static analyzers when used with Gitlab::Utils::Override#override
.
class A
include Gitlab::Utils::StrongMemoize
def do_something
# ...
end
strong_memoize_attr :do_something
end
class EE::A
extend Gitlab::Utils::Override
override :do_something
def do_something
super
# ...
end
end
A.prepend_mod
Alternative
diff --git a/lib/gitlab/ci/build/context/build.rb b/lib/gitlab/ci/build/context/build.rb
index a2b330f19b1a..f054c7f7a7e1 100644
--- a/lib/gitlab/ci/build/context/build.rb
+++ b/lib/gitlab/ci/build/context/build.rb
@@ -16,14 +16,13 @@ def initialize(pipeline, attributes = {})
end
def variables
- strong_memoize(:variables) do
- # This is a temporary piece of technical debt to allow us access
- # to the CI variables to evaluate rules before we persist a Build
- # with the result. We should refactor away the extra Build.new,
- # but be able to get CI Variables directly from the Seed::Build.
- stub_build.scoped_variables
- end
+ # This is a temporary piece of technical debt to allow us access
+ # to the CI variables to evaluate rules before we persist a Build
+ # with the result. We should refactor away the extra Build.new,
+ # but be able to get CI Variables directly from the Seed::Build.
+ stub_build.scoped_variables
end
+ strong_memoize_attr :variables
private
$ bin/rake lint:static_verification
# rake aborted!
# NotImplementedError: EE::A#do_something has arity of 0, but A#do_something has arity of -1
Example of failing CI job: https://gitlab.com/gitlab-org/gitlab/-/jobs/3428870435
Workaround
Using strong_memoize(:do_something) { ... }
works.
Edited by Peter Leitzen