Skip to content

Ruby: Block for steps into self parameters in trackModuleAccess#10895

Merged
hvitved merged 2 commits intogithub:mainfrom
hvitved:ruby/track-module-no-self-params
Oct 20, 2022
Merged

Ruby: Block for steps into self parameters in trackModuleAccess#10895
hvitved merged 2 commits intogithub:mainfrom
hvitved:ruby/track-module-no-self-params

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Oct 19, 2022

Since #10705, we apply an open-world assumption when resolving calls to singleton method, just like with calls to instance methods, so we should no longer track module accesses into self parameters. This removes false positive call graph edges like

class SingletonA
    def self.singleton1
    end

    def self.call_singleton1
        singleton1
    end

    def self.call_call_singleton1
        call_singleton1
    end
end

class SingletonB < SingletonA
    def self.singleton1
    end

    def self.call_singleton1
        singleton1 # should not be able to target `SingletonA:::singleton1` and `SingletonC:::singleton1`
    end
end

class SingletonC < SingletonA
    def self.singleton1
    end

    def self.call_singleton1
        singleton1 # should not be able to target `SingletonA:::singleton1` and `SingletonB:::singleton1`
    end
end

SingletonA.call_call_singleton1
SingletonB.call_call_singleton1
SingletonC.call_call_singleton1

Moreover, we were also not properly handling calls to self.new inside singleton methods defined via singleton classes.

@github-actions github-actions Bot added the Ruby label Oct 19, 2022
@hvitved hvitved force-pushed the ruby/track-module-no-self-params branch 2 times, most recently from 7cc806c to d69c622 Compare October 20, 2022 10:50
@hvitved hvitved force-pushed the ruby/track-module-no-self-params branch from d69c622 to faaead6 Compare October 20, 2022 11:00
@hvitved hvitved marked this pull request as ready for review October 20, 2022 11:02
@hvitved hvitved requested a review from a team as a code owner October 20, 2022 11:02
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Oct 20, 2022
@hvitved hvitved merged commit 471a596 into github:main Oct 20, 2022
@hvitved hvitved deleted the ruby/track-module-no-self-params branch October 20, 2022 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Ruby GA Ruby

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants