Skip to content

Fix sysread/read type corruption on tied scalars#248

Merged
fglock merged 2 commits intomasterfrom
fix-bytecode-my-extraction
Feb 27, 2026
Merged

Fix sysread/read type corruption on tied scalars#248
fglock merged 2 commits intomasterfrom
fix-bytecode-my-extraction

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Feb 27, 2026

Summary

  • Fix ClassCastException: TieScalar cannot be cast to String crash in op/gmagic.t caused by direct target.type field assignment corrupting tied scalar state after sysread/read
  • The BYTE_STRING type preservation (commit 8ee53eb) overwrote TIED_SCALAR type on tied variables while the value field still held the TieScalar object, causing later string access to fail with a cast exception
  • Guard both type assignments in sysread() and read() with a TIED_SCALAR check

Test plan

  • op/gmagic.t restored to 31/42 (matching master baseline)
  • All 154 unit tests pass (mvn test)

Generated with Devin

fglock and others added 2 commits February 27, 2026 10:59
BYTE_STRING fixes:
- substr on BYTE_STRING now preserves type instead of returning STRING
- 4-arg substr preserves BYTE_STRING type on extracted substring
- read() sets BYTE_STRING type for non-UTF8 file handles
- sysread returns BYTE_STRING via byte[] constructor in all IO classes

(@) prototype fix:
- handleListOrHashArgument no longer passes obeyParentheses=true to
  parseZeroOrMoreList, since outer parens are already consumed by
  consumeArgsWithPrototype. This fixes expressions like
  Set64u(($dat + 11644473600) * 1e7) being rejected as "Too many
  arguments" when the inner parens were misinterpreted as argument
  list delimiters.

Ref: #93

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
The BYTE_STRING type preservation added in 8ee53eb directly sets
target.type after sysread/read, which corrupts tied scalars by
overwriting their TIED_SCALAR type while the value field still holds
the TieScalar object. This causes a ClassCastException when the
scalar is later accessed as a string.

Guard the direct type assignments with a TIED_SCALAR check so tied
variables retain their proper type semantics.

Fixes gmagic.t regression (27/35 → 31/42).

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit c0ee472 into master Feb 27, 2026
2 checks passed
@fglock fglock deleted the fix-bytecode-my-extraction branch February 27, 2026 14:16
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