This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
Unsaved models can have nil non-nilable belongs-to relationships #253
Labels
bug
Something isn't working
Describe the bug:
The
belongs_to
relation is required by default (see #144) but objects with this relation don't necessarily have an object there. I believe the presence of the field is checked on save, not on construction. This leads to code which typechecks but fails withundefined method f for nil:NilClass
at runtime.Steps to reproduce:
I haven't had time to create a minimal reproduction, but:
belongs_to
relation between two ActiveRecord models.T.nilable
.It will result in
undefined method f for nil:NilClass
.Expected behavior:
The generated type should be T.nilable because there are no static constraints preventing this (at least for unsaved models).
Versions:
ruby 2.6.4p104 (2019-08-28) [x86_64-darwin17]
Rails 5.2.4.1
Sorbet typechecker 0.4.5144 git dbd5bee6b64af3f39b4291f64eec555f2fbb008f built on 2019-12-17 00:46:19 GMT debug_symbols=true
sorbet-rails (0.5.9.1)
The text was updated successfully, but these errors were encountered: