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

Optional parameter with wrong type default value is not treated as error #470

Closed
jljse opened this issue Dec 21, 2021 · 1 comment · Fixed by #578
Closed

Optional parameter with wrong type default value is not treated as error #470

jljse opened this issue Dec 21, 2021 · 1 comment · Fixed by #578
Labels
Milestone

Comments

@jljse
Copy link

jljse commented Dec 21, 2021

sig/test.rbs

class X
  def foo: (?String) -> void
end

test.rb

class X
  def foo(x = 1)
    p x
  end
end

X.new.foo('x')

These code doesn't show error.
I think default value 1 is error, because X#foo is explicitly typed.

My version is:
ruby 3.0.2p107
steep 0.47.0

@soutaro
Copy link
Owner

soutaro commented Jun 13, 2022

The original behavior was intentional. The x has a type of Integer | String and use of the variable inside the method will report an error.

The PR changes it to a type error to make things more explicit.

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

Successfully merging a pull request may close this issue.

2 participants