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

super and initialize related cases #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

handsomecheung
Copy link
Contributor

I found some cases about super and initialize:

  • super can refer to any methods, not only initialize

  • super can return a valid type

  • Class.new always returns an instance of Class, not same as initialize

  • missing popStack(call)
    if call super twice, the second super will return Type.UNKNOWN because the method which super refers to is still in stack.

class Base
  def initialize
    "init Base ok"
  end

  def self.get
    self.value
  end

  def self.value
    11235
  end
end

class Upper < Base
  def initialize
    s = super              # type of s marked as nil
    p s.class               # print String, type of `Base.initialize`
    "init Upper ok"
  end

  def self.value
    super
  end
end

Upper.new               # `Upper.new` be marked as str, because Upper.initialize is String
p Upper.new.class   # But `Upper.new` should be an instance of Upper

Upper.value               # marked as nil, since `super`returns nil
p Upper.value.class   # `super` in `self.value` refers to `Base.value`, not `Base.initialize` 

1, `super` may refer to any methods, not only `initialize`
2, missing `popStack(call)`
3, `Class.new` always returns <Class> type, not same as `initialize`
@yinwang0
Copy link
Owner

I'm afraid I don't have time to verify RubySonar code any more. If you want merge this commit, please do a larger scale run first to avoid possible problems.

@handsomecheung
Copy link
Contributor Author

I just test this change for some cases, so I am not sure if there are potential problems, especially for the method getOutterFunction. Maybe later I will do a large scale run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants