Support instance variables, class variables and class instance variables#149
Open
tk0miya wants to merge 3 commits intosoutaro:mainfrom
Open
Support instance variables, class variables and class instance variables#149tk0miya wants to merge 3 commits intosoutaro:mainfrom
tk0miya wants to merge 3 commits intosoutaro:mainfrom
Conversation
tk0miya
commented
Nov 22, 2024
Comment on lines
+488
to
+489
| # @rbs! type t = Prism::ClassVariableWriteNode | Prism::ClassVariableOrWriteNode | ||
| # | Prism::InstanceVariableWriteNode | Prism::InstanceVariableOrWriteNode |
Contributor
Author
There was a problem hiding this comment.
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 |
Contributor
Author
There was a problem hiding this comment.
I'm not sure this name is the best.
|
|
||
| current_decl.members << AST::Members::RubyDef.new(node, associated_comment, current_visibility, current_module_function, assertion) | ||
|
|
||
| instance_variables = MethodParser.parse(self, node) |
Contributor
Author
There was a problem hiding this comment.
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}" |
Contributor
Author
There was a problem hiding this comment.
I use #warn to warn duplications. Is there a better way to do that?
tk0miya
commented
Nov 22, 2024
a9777c2 to
26fefeb
Compare
tk0miya
commented
Nov 22, 2024
3bc7900 to
f243322
Compare
tk0miya
commented
Nov 22, 2024
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
tk0miya
commented
Nov 23, 2024
Comment on lines
+47
to
+49
| @tree: untyped | ||
|
|
||
| @source: untyped |
Contributor
Author
There was a problem hiding this comment.
attr_readers for these variables are defined in the base class. Therefore these definitions are bothersome...
c650b86 to
9f6cecd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: