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 in dyn_var implementation where returns from [] and * cause bug #73

Merged
merged 2 commits into from
Apr 22, 2024

Conversation

AjayBrahmakshatriya
Copy link
Collaborator

A recent change (#65) simplified the implementation of pointer types esp. struct types so that the overloaded * and [] operators returned dyn_var instead of builder. This allowed accessing members from these easier. However this causes a major bug where if the user writes code snippets like -

dyn_var<T*> ptr;
dyn_var<T> a = ptr[i];

the copy a is completely removed. This is because the operators construct the returned object using (builder::cast). Due to copy elision, a itself is constructed with (cast) causing errors. If a is used multiple times, each use will have ptr[i]. Bugs arise when ptr[i] has side effects.

This bug was discovered while implementing a toy language interpreter with @tekknolagi

To fix this issue, we introduce a clone of dyn_var called dyn_var_mimic which is exactly like dyn_var (inherits from dyn_var), but IS NOT dyn_var. We return this type from the operator. Thus is the user directly accesses the members, the behavior is the same like before, but if a dyn_var is constructed from such an expression, copy elision doesn't happen and a copy is created.

Minor change where dyn_var_parent_selector now strips of references from types before inheriting so dyn_var<T&> also have members. This is unrelated to above.

Sample38 is updated to test this.

@AjayBrahmakshatriya AjayBrahmakshatriya merged commit 175e4a2 into BuildIt-lang:master Apr 22, 2024
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