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
Steep ignores 3 nil checks on the same expression.
Offending code:
classEventattr_reader:pubkeyattr_accessor:id,:sigdefinitialize(pubkey:,id: nil,sig: nil)# <--- Note that id and sig can be nil@pubkey=pubkey@id=id@sig=sigenddefverify_signaturereturnfalseifid.nil? || pubkey.nil? || sig.nil?# <--- Ignored by Steepvalid_sig?(id,pubkey,sig)# <--- pubkey and sig should not be nil here. The line above ensures thatenddefvalid_sig?(message,public_key,signature)trueendend
RBS:
classEventattr_reader pubkey: String
attr_accessor id: String? # <--- id can be nilattr_accessor sig: String? # <--- sig can be nildef initialize: (pubkey: String, ?id: String?, ?sig: String?) -> voiddef verify_signature: -> booldef valid_sig?: (String, String, String) -> bool# <--- none can be nilend
Expected behaviour
No errors should be reported by Steep. The method valid_sig? requires non-nullable arguments. And the method verify_signatureensures that the arguments id, pubkey and sig are not null before calling the method valid_sig?.
$ bundle exec steep check
# Type checking files:
.....................................................................................
No type error detected. 🫖
Actual behaviour
The following error is reported by Steep:
$ bundle exec steep check
nostr.rb:24:27: [error] Cannot pass a value of type `(::String | nil)` as an argument of type `::String`
│ (::String | nil) <: ::String
│ nil <: ::String
│
│ Diagnostic ID: Ruby::ArgumentTypeMismatch
│
└ crypto.valid_sig?(id, pubkey, sig)
~~~
Detected 1 problem from 1 file
But only when the 3 nil checks on the same expression. Fewer nil checks do not trigger the error.
Problem
Steep ignores 3
nil
checks on the same expression.Offending code:
RBS:
Expected behaviour
No errors should be reported by Steep. The method
valid_sig?
requires non-nullable arguments. And the methodverify_signature
ensures that the argumentsid
,pubkey
andsig
are not null before calling the methodvalid_sig?
.Actual behaviour
The following error is reported by Steep:
But only when the 3 nil checks on the same expression. Fewer nil checks do not trigger the error.
Workaround
Use 2 or fewer nil checks on the same expression.
Steps to reproduce
git clone git@github.com:wilsonsilva/steep-nil-argument-type-mismatch-bug.git
bundle install
bundle exec steep check
Environment
3.3.0
1.6.0
3.4.4
macOS Sonoma 14.4 (23E214)
A tiny sample project to reproduce the problem https://github.com/wilsonsilva/steep-nil-argument-type-mismatch-bug
The text was updated successfully, but these errors were encountered: