-
Notifications
You must be signed in to change notification settings - Fork 13
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
Support instance variables, class variables and class instance variables #149
base: main
Are you sure you want to change the base?
Conversation
# @rbs! type t = Prism::ClassVariableWriteNode | Prism::ClassVariableOrWriteNode | ||
# | Prism::InstanceVariableWriteNode | Prism::InstanceVariableOrWriteNode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to give a better name for such type alias. Please let me know if you have opinions.
|
||
# @rbs node: t | ||
# @rbs annotation: Annotations::TypeAssertion? | ||
# @rbs scope: :class | :method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this name is the best.
@@ -258,6 +258,9 @@ def visit_def_node(node) | |||
assertion = assertion_annotation(node.rparen_loc || node&.parameters&.location || node.name_loc) | |||
|
|||
current_decl.members << AST::Members::RubyDef.new(node, associated_comment, current_visibility, current_module_function, assertion) | |||
|
|||
instance_variables = MethodParser.parse(self, node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MethodParser? RubyDefParser? DefNodeParser?
lib/rbs/inline/writer.rb
Outdated
if var.type != untyped | ||
case decl | ||
when AST::Declarations::ClassDecl | ||
warn "error: duplicate variable #{var.name} in #{decl.class_name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use #warn
to warn duplications. Is there a better way to do that?
a9777c2
to
26fefeb
Compare
3bc7900
to
f243322
Compare
This adds support for instance variables, class variables and class instance variables. After this change, RBS::Inline can extract them from assignment for these variables. Example: ```ruby class Example def method @ivar = 123 #: Integer @@cvar = "blah blah" #: String end end ``` ```rbs class Example def method: () -> untyped @ivar: Integer @@cvar: String end ```
f243322
to
c6ca380
Compare
@tree: untyped | ||
|
||
@source: untyped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attr_readers for these variables are defined in the base class. Therefore these definitions are bothersome...
c650b86
to
9f6cecd
Compare
This adds support for instance variables, class variables and class instance variables.
After this change, RBS::Inline can extract them from assignment for these variables.
Example: