Skip to content

super and initialize related cases#16

Open
handsomecheung wants to merge 2 commits into
yinwang0:masterfrom
handsomecheung:b-super-init
Open

super and initialize related cases#16
handsomecheung wants to merge 2 commits into
yinwang0:masterfrom
handsomecheung:b-super-init

Conversation

@handsomecheung

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants