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

v: if guard optional: Define err and errcode in else branch #5853

Merged
merged 5 commits into from
Jul 17, 2020

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Jul 16, 2020

Also:

  • cgen: Don't allocate guard_vars array until there's a guard
  • parser: Use if sum is T instead of sum as T
  • parser: Rename is_or variable to is_guard

// only declare `err` if previous branch was an `if` guard
if prev_guard {
p.open_scope()
p.scope.register('err', ast.Var{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to also do p.scope.register('errcode', ast.Var{ here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now done. I think we need a TODO for the docs that it's required to update when making undocumented changes, errcode is not documented. I'm also concerned that Option is too big to use as a true option type (i.e. without error fields). For that it should only be the size of a pointer if the element type is a pointer, setting the lowest bit when none, and not add more than a word for non-pointer element types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be optimized. If error fields are not used, it will be a small type with just one extra boolean field.

@ntrel ntrel changed the title v: if guard optional: Define err in else branch v: if guard optional: Define err and errcode in else branch Jul 17, 2020
@medvednikov medvednikov merged commit 39f90e2 into vlang:master Jul 17, 2020
@ntrel ntrel deleted the if-err branch July 19, 2020 20:24
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.

None yet

3 participants