Skip to content

self refers to current class#17

Open
handsomecheung wants to merge 1 commit into
yinwang0:masterfrom
handsomecheung:b-self-to-current-cls
Open

self refers to current class#17
handsomecheung wants to merge 1 commit into
yinwang0:masterfrom
handsomecheung:b-self-to-current-cls

Conversation

@handsomecheung

Copy link
Copy Markdown
Contributor
class Base
  def self.get
    self.value
  end

  def self.value
    :hello
  end
end

class Upper1 < Base
  def self.value
    "hello"
  end
end

Upper1.get         # () -> symbol

The type of Upper1.get should be string. I add a binding self to current class (Upper1) to make the type right.

But this change will trigger a new issue:

class Upper1 < Base
  def self.value
    "hello"
  end
end

class Upper2 < Base
  def self.value
    11235
  end
end

Upper1.get    # () -> str
Upper2.get    # () -> str

Upper1.get and Upper2.share the same base method Base.get, so they are same type because of cache.

I don't know how to solve this issue simply, maybe change structure of arrows?

@yinwang0

Copy link
Copy Markdown
Owner

Ideally this can return a union type. But we can leave it this way now because the code requiring a union type in fields is bad style.

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