Skip to content

Fix generic struct pointer instantiation bug #105#109

Merged
Zuhaitz-dev merged 9 commits intozenc-lang:mainfrom
iryuken:main
Jan 25, 2026
Merged

Fix generic struct pointer instantiation bug #105#109
Zuhaitz-dev merged 9 commits intozenc-lang:mainfrom
iryuken:main

Conversation

@iryuken
Copy link
Copy Markdown
Contributor

@iryuken iryuken commented Jan 24, 2026

bug where generic structs referenced only via pointers (for example,
RcInner<T>* inside Rc<T>) were not being instantiated, leading to compilation errors.

The issue stemmed from the parser discarding structured type information for struct
fields and the instantiation logic failing to recurse into generic pointer types.
As a result, dependencies nested deep within generic struct definitions were not
detected or generated.

issue #105

What Changed

  • The parser now preserves full structured type information for struct fields,
    ensuring generic relationships are retained.
  • The instantiation logic has been enhanced to recursively generate code for
    nested generic pointer types.
  • Name parsing issues related to generic pointer instantiation were fixed.

Verification

This behavior is verified by the included Rc<T> test case. When Rc<i32> is used,
the compiler now correctly instantiates RcInner_int32_t, confirming that generic
dependencies referenced only through pointers are properly detected and generated.

Files Changed

@iryuken iryuken marked this pull request as draft January 24, 2026 06:32
@iryuken
Copy link
Copy Markdown
Contributor Author

iryuken commented Jan 24, 2026

Regression Fixes & Improvements

While verifying the generic struct pointer fix, I identified and resolved two additional regressions:

  1. derive(Eq) for Pointer Fields:
    The derive(Eq) macro was incorrectly generating deep equality checks (Vec_T__eq) for pointer fields like Vec<T>*, causing compilation errors. I updated parser_core.c to enforce shallow pointer comparison (ptr1 == ptr2) for pointer fields, and refined parser_expr.c to prevent the parser from rewriting == to .eq() calls unless both operands are strict value types (preserving operator overloading correctness).

  2. Strict Type Checking Adjustments:
    Adjusted type compatibility rules in parser_expr.c to explicitly allow initialization of pointers with 0 (null) and to support mixed arithmetic/comparison between standard numeric types, which strict mode had inadvertently flagged.

@iryuken
Copy link
Copy Markdown
Contributor Author

iryuken commented Jan 24, 2026

Any thoughts on adding a debug branch?

@iryuken iryuken marked this pull request as ready for review January 24, 2026 07:41
@Zuhaitz-dev
Copy link
Copy Markdown
Member

Looks good, I am not home, but there I will check it properly and surely merge it.

Related to a debug branch, I don't think it would be a bad idea. What I do think is that we should have an experimental branch or similar.

The language is still green, but having something like this would be useful already.

@iryuken iryuken changed the title Fix generic struct pointer instantiation bug #105 Fix generic struct pointer instantiation bug #105 Jan 25, 2026
@Zuhaitz-dev
Copy link
Copy Markdown
Member

Looks good to me

@Zuhaitz-dev Zuhaitz-dev merged commit b568f67 into zenc-lang:main Jan 25, 2026
3 checks passed
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.

2 participants