Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten arity of value and object fields #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Bo98
Copy link
Contributor

@Bo98 Bo98 commented Mar 11, 2025

Tapioca isn't currently importing all the field signatures correctly. You can see that at kuby-core where in ObjectMeta the annotations signature is imported but most of the others are not: https://github.com/getkuby/kuby-core/blob/master/sorbet/rbi/gems/kube-dsl%400.8.0.rbi#L9080-L9088

This is because Tapioca sees the method definitions having a different parameter signature to the RBIs due to the use of *args. When in this situation, Tapioca currently chooses to ignore the RBI.

To fix this I tightened the arity of value and object fields (i.e. removed *args). I kept backwards compatibility as much as possible except for two small breaks, though they are unlikely to be hit by anyone:

  • This now correctly errors at runtime (previously just ignored further arguments):
KubeDSL.namespace do
  metadata do
    name "my-namespace", "other argument"
  end
end
  • Object field positional arguments are no longer supported (and never was in RBIs nor the generator anyway):
class Test < KubeDSL::DSLObject
  object_field(:weird_field) { |some_arg| some_arg ? KubeDSL.object_meta : KubeDSL.list_meta }
end

Test.new do
  weird_field(true) do
    puts "1: weird_field(true) = #{self.class}"
  end
end

Test.new do
  weird_field(false) do
    puts "2: weird_field(false) = #{self.class}"
  end

  weird_field(true) do
    # will not change it from false
    puts "2: weird_field(true) = #{self.class}"
  end
end

# OLD BEHAVIOUR:
# 1: weird_field(true) = KubeDSL::DSL::Meta::V1::ObjectMeta
# 2: weird_field(false) = KubeDSL::DSL::Meta::V1::ListMeta
# 2: weird_field(true) = KubeDSL::DSL::Meta::V1::ListMeta

# NEW BEHAVIOUR:
# lib/kube-dsl/value_fields.rb:32:in `block in object_field': wrong number of arguments (given 1, expected 0) (ArgumentError)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant