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

self refers to current class #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

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

None yet

2 participants