Skip to content

Bugfixes & refactors batch August 8, 2026 - #2303

Merged
SchoolyB merged 37 commits into
mainfrom
bugfixes/august-8-2026
Aug 8, 2026
Merged

Bugfixes & refactors batch August 8, 2026#2303
SchoolyB merged 37 commits into
mainfrom
bugfixes/august-8-2026

Conversation

@SchoolyB

@SchoolyB SchoolyB commented Aug 8, 2026

Copy link
Copy Markdown
Member

This PR contains several bugfixes as well as changes focusing on maintainability and readability through refactors, performance and optimization improvments.

Summary

Bugfixes

  • fix implicit enum selector resolution in map keys/values/struct defaults
  • fix multi-return rejection in 5 expression contexts
  • fix tagged enum interpolation/map-value rejection
  • fix correct narrowing hint to use cast() syntax
  • fix compound types in tagged enum payloads
  • fix element types for arrays.fill/append/insert_at/prepend with wide ints/char/byte/enums
  • fix explicit deref syntax that broke struct function calls
  • fix or_return fallback count
  • fix quoted field unescaping in@csv stdlib module
  • fix parameterized queries in @sqlite stdlib module
  • added a CLI unknown command error message

Maintainability and performance optimizations/refactors

  • consolidate panic functions and ANSI colors
  • extract gray_cstr() helper
  • add GROW_ARRAY macro
  • add integer type name predicates
  • add temp variable counters
  • UTF-8 encode/decode dedup
  • shared conversion validation
  • add ARRAY_CHECK_ITER guard macro
  • add print function macro generation
  • when-pattern speculative parse dedup, binary codec macro

SchoolyB and others added 30 commits August 6, 2026 02:22
…end (#2242)

The codegen for arrays.append, insert_at, and prepend was missing TK_ENUM
handling in the element type switch, causing it to fall through to the
__auto_type default. This produced sizeof(__auto_type) which is invalid C.
Now resolves enum types via gray_type_to_c_codegen to emit the correct
GrayEnum_<Name> type.
fix(codegen): emit concrete enum type in arrays.append/insert_at/prepend (#2242)
Add sqlite.exec_params and sqlite.query_params functions that accept
a SQL string with ? placeholders and a [string] params array, binding
values via sqlite3_bind_text to prevent SQL injection. Parameters are
bound as text; SQLite handles type affinity internally.
fix(stdlib): add parameterized query API to sqlite module (#1690)
fix(typechecker): resolve implicit enum selectors in struct field defaults (#2223)
fix(stdlib): unescape doubled quotes in csv.parse() quoted fields (#2239)
fix(typechecker): resolve implicit enum selectors in map key bracket access (#2246)
…acros (#2275)

Extract duplicated ANSI color macros from error.c and runtime.c into a
shared util/colors.h header, and consolidate three near-identical panic
functions into a single gray_panic_impl() with thin public wrappers.
…2282)

Replace identical static GrayString-to-C-string helpers in net.c,
http.c, and regex.c with a single gray_cstr() inline in runtime.h.
Also simplify the inline copy in regex.c's compile_pattern().
…#2271)

Define a reusable GROW_ARRAY macro in xalloc.h with a named
GROW_ARRAY_INIT_CAP constant, replacing 16 inline capacity-doubling
blocks across typechecker.c and codegen.c.
…#2270)

Move is_unsigned_type, is_signed_int_type, and is_bigint_type from
static functions in typechecker.c/codegen.c into shared static inline
predicates in types.h. Add is_any_int_type and use it to replace
inline strcmp chains in typechecker.c and parser.c.
…#2278)

Extract shared cp_to_utf8() and utf8_next() helpers, replacing 3 copies
of the encoding cascade and 2 copies of the decoding cascade.
…rconv.c (#2286)

Replace 7 copies of the truncate+copy+null-terminate sequence with a
shared strconv_prepare() helper.
…2285)

Replace 12 identical iteration guard checks with a single macro.
…2248)

Enum arrays were read as int64_t (8 bytes) during string interpolation
but C enums are stored as int (4 bytes), causing overlapping reads that
produced garbage values.
…#2261)

Tagged enums are C structs, but interpolation and map codegen paths
treated them as int64_t, leaking raw C compiler errors. Add E3041 check
for interpolation and new E5041 for map value type declarations.
The parser was counting individual tokens inside tagged enum variant
payload parentheses instead of parsing complete type expressions.
This caused ^T to be counted as 2 payloads, [T] as 3, and map[K:V]
as 6. Replace token counting with parse_complex_type() calls.
…/prepend (#2297)

The element type switch in append, insert_at, and prepend was missing
TK_CHAR and TK_BYTE cases, causing the codegen to fall through to
__auto_type which is not valid in sizeof(). Add char → int32_t and
byte → uint8_t mappings.
…t/prepend (#2298)

i128/u128/i256/u256 share TK_INT/TK_UINT as their kind, so the element
type switch mapped them to int64_t/uint64_t instead of gray_i128 etc.
After the switch, resolve via gray_type_to_c_codegen when the kind is
TK_INT or TK_UINT to pick up the correct wide type from the name.
The fill codegen path only handled float, bool, and string. Add char,
byte, array, map, struct, enum, and wide int (i128/u128/i256/u256)
element type mappings, consistent with append/insert_at/prepend.
…2244)

p^.func() was rejected as a chained call (E3075) because the member
expression object was NODE_POSTFIX_EXPR, not NODE_LABEL. Extend the
instance dispatch condition to also accept explicit dereferences of
labels. When rewriting the AST for dispatch, replace the postfix node
with a fresh NODE_LABEL so the struct name assignment doesn't corrupt
the union.
…on (#2277)

Replace 4 near-identical copy-pasted families (print/println/eprint/eprintln × 7 types) with 7 core helpers and a PRINT_FAMILY macro that stamps out the 28 public wrappers.
#2280)

Consolidate identical encode_le, encode_be, decode_le, and decode_be patterns into BINARY_CODEC macro for flat types (16-64 bit ints + floats). 128/256-bit BE decoders kept hand-written due to multi-limb struct layout.
Extract ParserSnapshot save/restore and scan_paren_bindings helper to replace three near-identical speculative parse blocks for when-pattern detection (explicit, qualified, implicit forms).
@SchoolyB SchoolyB added bug Something isn't working parser Related to parsing and AST construction typechecker Related to type checking and validation stdlib General standard library issues code-quality Code cleanup, linting, and static analysis fixes labels Aug 8, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests Related to unit tests or test infrastructure error-messages Related to improving error messages cli Command-line interface related grayc Related to the grayscale compiler core or its internal tooling labels Aug 8, 2026
@SchoolyB SchoolyB changed the title Bugfixes & refactors batch — August 8, 2026 Bugfixes & refactors batch August 8, 2026 Aug 8, 2026
@SchoolyB
SchoolyB merged commit 2589349 into main Aug 8, 2026
@SchoolyB
SchoolyB deleted the bugfixes/august-8-2026 branch August 8, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cli Command-line interface related code-quality Code cleanup, linting, and static analysis fixes documentation Improvements or additions to documentation error-messages Related to improving error messages grayc Related to the grayscale compiler core or its internal tooling parser Related to parsing and AST construction stdlib General standard library issues tests Related to unit tests or test infrastructure typechecker Related to type checking and validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant