From be3a312ca7e5f7e0a24c3a6eb52e721d8af47e41 Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Wed, 7 Feb 2024 20:10:33 +0900 Subject: [PATCH] Fix steep check offense MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` ❯ bundle exec rake steep bundle exec steep check # Type checking files: .............................................................................................................................F......................... lib/lrama/grammar/symbols/resolver.rb:201:33: [error] Cannot pass a value of type `(::Integer | nil)` as an argument of type `::Integer` │ (::Integer | nil) <: ::Integer │ nil <: ::Integer │ │ Diagnostic ID: Ruby::ArgumentTypeMismatch │ └ sym.token_id = Integer($1, 8) ~~~~~~~~~~~~~~ lib/lrama/grammar/symbols/resolver.rb:203:36: [error] Type `(::String | nil)` does not have method `bytes` │ Diagnostic ID: Ruby::NoMethod │ └ sym.token_id = $1.bytes.first ~~~~~ Detected 2 problems from 1 file ``` --- lib/lrama/grammar/symbols/resolver.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/lrama/grammar/symbols/resolver.rb b/lib/lrama/grammar/symbols/resolver.rb index f34b9b2e..07e03e70 100644 --- a/lib/lrama/grammar/symbols/resolver.rb +++ b/lib/lrama/grammar/symbols/resolver.rb @@ -198,9 +198,17 @@ def fill_terms_number when "\\\\" sym.token_id = 92 when /\A\\(\d+)\z/ - sym.token_id = Integer($1, 8) + unless (id = Integer($1, 8)).nil? + sym.token_id = id + else + raise "Unknown Char s_value #{sym}" + end when /\A(.)\z/ - sym.token_id = $1.bytes.first + unless (id = $1&.bytes&.first).nil? + sym.token_id = id + else + raise "Unknown Char s_value #{sym}" + end else raise "Unknown Char s_value #{sym}" end