You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
app/models/health.rb:8:6: [error] Cannot assign a value of type `(::Integer | nil)` to a variable of type `::Integer`
│ (::Integer | nil) <: ::Integer
│ nil <: ::Integer
│
│ Diagnostic ID: Ruby::IncompatibleAssignment
│
└ @value = [
~~~~~~~~~~
app/models/health.rb:17:6: [error] Cannot assign a value of type `(::Integer | nil)` to a variable of type `::Integer`
│ (::Integer | nil) <: ::Integer
│ nil <: ::Integer
│
│ Diagnostic ID: Ruby::IncompatibleAssignment
│
└ @value = [
Looks like the Array#min is saying it can return nil, which for an empty array would be the case ([].max => nil), but the array has a static Integer in it (100), so [100].max can never return nil. Additionally, the amount argument and value reader are also of type ::Integer, not ::Integer?, which means both elements in the array will always contain a value from a typing perspective...
This error should not show in cases where the type check determines that there will always be at least one non-nil value in the array.
The text was updated successfully, but these errors were encountered:
KieranP
changed the title
Latest master introduced false positives
Incorrrect IncompatibleAssignment error in Array#min with a static value
Dec 6, 2024
In the latest release (1.9), and starting to see IncompatibleAssignment errors where I did not previously.
Looks like the Array#min is saying it can return nil, which for an empty array would be the case (
[].max => nil
), but the array has a static Integer in it (100
), so[100].max
can never return nil. Additionally, theamount
argument andvalue
reader are also of type ::Integer, not ::Integer?, which means both elements in the array will always contain a value from a typing perspective...This error should not show in cases where the type check determines that there will always be at least one non-nil value in the array.
The text was updated successfully, but these errors were encountered: