Fix TestDataHandler's DataType.ANY and PAIR/ARRAY handling - #859
Merged
Conversation
Two bugs in the shared testplugin test double surfaced by binary_tree's regression test for #813 (accepting DataType.ARRAY as equally valid to PAIR for tree nodes): 1. matchesType() special-cases DataType.LIST (PAIR or EMPTY_LIST) but not DataType.ANY - it fell through to `value.type === expected`, requiring a value's own type tag to literally be ANY, which per conductor's own isSameType() (`t1 === DataType.ANY || t2 === DataType.ANY` => true) and isReferenceType()'s doc comment ("never a value's own type tag; only ever a declared parameter type") is backwards: ANY as a declared/expected type must match any value. array_set(arr, i, v) on an array_make(DataType.ANY, ...) array threw "Array element expected ANY, got EMPTY_LIST" for exactly this reason. 2. getPair() (the single choke point pair_head/pair_tail/pair_sethead/ pair_settail/pair_assert all use) only ever looked up pairMap, so a value tagged DataType.ARRAY - which per binary_tree's own comment ("a pair is just an array of length 2 - no distinct pair representation") pair_head/pair_tail are expected to accept transparently, matching the real evaluator - threw "Unknown pair identifier N" instead of falling back to arrayMap. Both were invisible until a test actually built a tree entirely out of array_make/array_set (simulating a tree round-tripped back in through Python) rather than pair_make, which is exactly what #813's regression test does.
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the failing `binary_tree Bundle` CI job — same failure reported earlier and confirmed pre-existing, unrelated to the `@sourceacademy/conductor` version bump (#858). Root cause was two bugs in `lib/testplugin`'s shared test double, both invisible until #813's regression test built a tree entirely out of `array_make`/`array_set` (simulating a tree round-tripped back in through Python) instead of `pair_make`.
Bug 1 — `matchesType()` didn't special-case `DataType.ANY`. It already special-cases `DataType.LIST` (matching `PAIR` or `EMPTY_LIST`), but for `ANY` it fell through to `value.type === expected` — requiring a value's own type tag to literally be `ANY`. That's backwards: per conductor's own `isSameType()` (`t1 === DataType.ANY || t2 === DataType.ANY` → `true`) and `isReferenceType()`'s doc comment ("never a value's own type tag; only ever a declared parameter type"), `ANY` as a declared type must match any value. This produced:
```
Error: Array element expected ANY, got EMPTY_LIST.
```
Bug 2 — `getPair()` (the single choke point every `pair_*` method uses) only ever looked up `pairMap`. Per `binary_tree`'s own comment ("a pair is just an array of length 2 - no distinct pair representation"), `pair_head`/`pair_tail` are expected to transparently accept a value tagged `DataType.ARRAY`, matching the real evaluator. `getPair` had no fallback to `arrayMap`, producing:
```
Error: Unknown pair identifier 3.
```
Verification
🤖 Generated with Claude Code