soutaro / steep

Static type checker for Ruby
MIT License
1.35k stars 85 forks source link

Record Type allows non-defined keys #1046

Open richardboehme opened 7 months ago

richardboehme commented 7 months ago

When defining a record type, I expected the type checker to complain if an additional (non-defined) key was supplied by the user. Specifically I expected the following to fail type checking:

# @type var x: { name: String }
x = { name: "foo", bar: 'foo' }

Is my assumption wrong or is this a bug in Steep? Might it be related with the change in #256?

Version tested: 1.6.0

soutaro commented 7 months ago

It makes sense. Reporting unknown keys included in literals should help.

ParadoxV5 commented 6 months ago

Comment moved from #256

  • Allows skipping nil-able attributes
# @type var x: { name: String, email: String? }
x = { name: "foo" }                                    # OK 🐕 

Ackchyually nonexistent key is distinguishable from nil values for non-implicit-nil methods such as x.fetch :email.

# @type var x: { name: String, ?email: String? }
x = { name: "foo" }  # OK 💯

P.S. see ruby/rbs#504 regarding ?email: