Skip to content

Fix TypeChecker::Rules#level always returning nil - #1333

Open
apiology wants to merge 2 commits into
castwide:masterfrom
apiology:fix-typechecker-rules-level
Open

apiology wants to merge 2 commits into
castwide:masterfrom
apiology:fix-typechecker-rules-level

Conversation

@apiology

Copy link
Copy Markdown
Contributor

Claude:

Problem:

TypeChecker::Rules#level (attr_reader :level, documented @return [Symbol]) has silently returned nil since it was introduced in 2020 (38e0da2a9, PR #311), and it's public API via the public attr_reader TypeChecker#rules.

LEVELS = { normal: 0, typed: 1, strict: 2, strong: 3, alpha: 4 }.freeze
@rank = LEVELS[level]        # level: Symbol → @rank: Integer
@level = LEVELS[LEVELS.values.index(@rank)]

LEVELS.values.index(@rank) returns an Integer, and indexing the Symbol-keyed LEVELS hash with an Integer never matches any key.

Solution:

Replace the broken reverse lookup with LEVELS.key(@rank), Hash#key's correct value-to-key lookup, and add a regression spec.

Rules#initialize computed the level by indexing LEVELS (a
Symbol-keyed Hash) with LEVELS.values.index(@rank), an Integer.
That lookup never matches a Symbol key, so level was always nil at
runtime despite being documented to return a Symbol.

Use Hash#key(value) instead, the correct reverse lookup from rank
back to its level symbol. Adds a regression spec asserting #level
returns the expected Symbol.
@apiology
apiology marked this pull request as ready for review August 27, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant