Skip to content

KeywordArgs deficiencies? #282

@indigoviolet

Description

@indigoviolet

The KeywordArgs contract appears to have two deficiencies:

  1. A missing arg with a Maybe[] contract is valid despite not being declared optional
[9] development (main)> kk = Contracts::KeywordArgs[a: Contracts::Maybe[String]]
[10] development (main)> kk.valid?({})
=> true

In practice, this is often not an issue because the function definition would be like

Contract Contracts::KeywordArgs[a: Contracts::Maybe[String]]
def foo(a: )
end

and Ruby would enforce the presence of a.

However this would break in the more esoteric case of

Contract Contracts::KeywordArgs[a: Contracts::Maybe[String]]
def foo(**kwargs)
end
  1. Default values for optional args are not validated by Contracts
[6] development (main)> module Foo
[6] development (main)*   Contract KeywordArgs[a: Optional[String]] => Any
[6] development (main)*   def self.foo(a: 2)
[6] development (main)*   end
[6] development (main)* end

[7] development (main)> Foo.foo
=> nil

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions