diff options
| author | Patrick Simianer <patrick@lilt.com> | 2026-02-24 17:18:29 +0100 |
|---|---|---|
| committer | Patrick Simianer <patrick@lilt.com> | 2026-02-24 17:18:29 +0100 |
| commit | 4e62908a1757f83ff703399252ad50758c4eb237 (patch) | |
| tree | ef7a525a7109f825cfa9b9369e28f2877ff4590b /prototype | |
| parent | 22dc0fbdf002c7824941abc17a715a3e70ff37c1 (diff) | |
Replace silent rescue with explicit type check in Item constructor
When creating an Item from a Rule (not an Item), tail_spans doesn't exist.
Check with is_a?(Item) instead of catching the exception silently.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'prototype')
| -rw-r--r-- | prototype/parse.rb | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/prototype/parse.rb b/prototype/parse.rb index adf2b91..40a69e7 100644 --- a/prototype/parse.rb +++ b/prototype/parse.rb @@ -90,14 +90,10 @@ class Item < Grammar::Rule rule_or_item.rhs.each_with_index { |x,i| # duplicate rhs partially @rhs << x if x.class == Grammar::NT - begin - if i >= dot - @tail_spans[i] = Span.new(-1, -1) - else - @tail_spans[i] = rule_or_item.tail_spans[i].dup - end - rescue + if i >= dot || !rule_or_item.is_a?(Item) @tail_spans[i] = Span.new(-1, -1) + else + @tail_spans[i] = rule_or_item.tail_spans[i].dup end end } |
