Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with dyn_var<T*> requiring T to be completely defined #92

Merged

Conversation

AjayBrahmakshatriya
Copy link
Collaborator

BuildIt had a bug with how it handles dyn_var<T*> for recursive types. A very common pattern like the following appears in linked list implementations -

struct linked_list {
    dyn_var<linked_list*> next;
};

Typically declaring a pointer to a type doesn't require the type to be "complete". However the way dyn_var<T*> is implemented is it tries to create an object of type dyn_var inside to return when the ->/[] operator is called. Now this causes issues because dyn_var requires T to be "complete" since it inherits from T when T is a struct type.

This causes the above sample to fail with compile error.

To fix this we make the extra member of type dyn_var inside dyn_var<T*> be created lazily. We change the member to be of type std::unique_ptr<dyn_var> and allocate it when it is first required.

Sample63 has been added to test this

@AjayBrahmakshatriya AjayBrahmakshatriya merged commit 14cd7fc into BuildIt-lang:master Mar 2, 2025
2 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.

1 participant