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

Compiler: correct to handle instance variable assignment inside block on global #4324

Merged

Conversation

makenowjust
Copy link
Contributor

# `InstanceVar` assignment appered in block is not checked
# by `Crystal::InstanceVarsInitializerVisitor` because this block
# may be passed to a macro. So, it checks here.
if current_type.is_a?(Program) || current_type.is_a?(FileModule)
Copy link
Member

@bcardiff bcardiff May 4, 2017

Choose a reason for hiding this comment

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

Shouldn't the check be with!current_type.is_a?(InstanceVarContainer)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologize for the late reply. I missed your comment, sorry...

For example, InstanceVarsInitializerVisitor treats only Program and FileModule as global type. (here)
Perhaps your suggestion is correct, but I don't know really.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was considering, then I think !current_type.is_a?(InstanceVarContainer) is not needed because available not InstanceVarContainer current_type is one of EnumType and LibType as I know, but both type's body cannot contain assignment (and any expressions). Even if enum or lib allow to include macro calls in body, assignment is rejected on parse phase, I think.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, i think you are right since FileModule < NonGenericModuleType < InstanceVarContainer.

Copy link
Member

Choose a reason for hiding this comment

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

And there are other places where Program and FileModule are used as a condition.

@makenowjust makenowjust force-pushed the fix/crystal/ivar-in-block-global branch from 69ef537 to 29aebd6 Compare May 26, 2017 09:33
makenowjust added a commit to makenowjust/crystal that referenced this pull request May 26, 2017
@bcardiff bcardiff merged commit 3961dd0 into crystal-lang:master May 26, 2017
@bcardiff
Copy link
Member

Thanks @makenowjust 🙇

@bcardiff bcardiff added this to the Next milestone May 26, 2017
@makenowjust makenowjust deleted the fix/crystal/ivar-in-block-global branch May 26, 2017 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants