Skip to content

Commit

Permalink
Ruby: recognize "include" in a singleton method as a mixin instruction
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Apr 1, 2020
1 parent 205052c commit f9a77b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Units/parser-ruby.r/ruby-mixin-field.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ Y input.rb /^module Y$/;" m
hoi input.rb /^ def hoi$/;" f module:Y
A input.rb /^class A$/;" c mixin:include:X,include:Y
hi input.rb /^ def hi$/;" f class:A
B input.rb /^class B$/;" c mixin:include:X
prep input.rb /^ def self.prep$/;" S class:B
6 changes: 6 additions & 0 deletions Units/parser-ruby.r/ruby-mixin-field.d/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ def hi
end
include Y
end

class B
def self.prep
include X
end
end
8 changes: 8 additions & 0 deletions parsers/ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,14 @@ static void readAndStoreMixinSpec (const unsigned char** cp, const char *how_mix
NestingLevel *nl = nestingLevelsGetCurrent (nesting);
tagEntryInfo *e = getEntryOfNestingLevel (nl);

if (e->kindIndex == K_SINGLETON)
{
nl = nestingLevelsGetNth (nesting, nesting->n - 2);
if (nl == NULL)
return;
e = getEntryOfNestingLevel (nl);
}

if (! (e->kindIndex == K_CLASS || e->kindIndex == K_MODULE))
return;

Expand Down

0 comments on commit f9a77b5

Please sign in to comment.