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

Fix: Instance vars should not be allowed on Class, Tuple, NamedTuple, Enum, Pointer , Proc, StaticArray and Union. #12160

Merged
merged 2 commits into from Jul 15, 2022

Conversation

I3oris
Copy link
Contributor

@I3oris I3oris commented Jun 25, 2022

Fix #12159.

The compiler now produce an error when user define an ivar on these types: Class, Tuple, NamedTuple, Enum, Pointer , Proc, StaticArray and Union.

class Class
  @x = 42
end
# => Error: can't declare instance variables in Class

(similar to previously triggered errors on forbidden types Int32 Number, Object...)

Note that TupleInstanceType or NamedTupleInstanceType still inherit from module InstanceVarContainer through GenericClassInstanceType, but couldn't touch that because GenericClassInstanceType is used by every generic class.

…uple`, `Enum`, `Pointer` , `Proc`, `StaticArray` and `Union`.
Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

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

I think the direct enumeration is OK, as is a more abstract approach as suggested here.

Thanks @I3oris !

@I3oris
Copy link
Contributor Author

I3oris commented Jul 11, 2022

Okay super!, thanks.

@straight-shoota straight-shoota added this to the 1.6.0 milestone Jul 12, 2022
@beta-ziliani beta-ziliani self-assigned this Jul 12, 2022
@straight-shoota straight-shoota merged commit 7a0c931 into crystal-lang:master Jul 15, 2022
@I3oris I3oris deleted the bug/tuple_instance_vars branch September 2, 2022 21:52
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.

Instance vars should not be allowed on Class, Tuple, NamedTuple, Enum, Pointer , Proc, StaticArray and Union.
4 participants