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

Steep doesn't check assignment to Instance Variables #1478

Open
radiantshaw opened this issue Jan 21, 2025 · 2 comments
Open

Steep doesn't check assignment to Instance Variables #1478

radiantshaw opened this issue Jan 21, 2025 · 2 comments

Comments

@radiantshaw
Copy link

Assume the following RBS file:

class Foobar
  @baz: Integer

  def initialize: (Integer baz) -> void
end

and the following Ruby file:

class Foobar
  def initialize(baz)
    @baz = baz.to_s
  end
end

The above should give a warning about assigning type ::String to an instance variable of type ::Integer, but it doesn't.

@tk0miya
Copy link
Contributor

tk0miya commented Feb 12, 2025

Reproduced on my local.

This is not a bug of Steep. It's a bug of type of activesupport gem.

For example, I replaced baz.to_s with a string literal. Then Steep emits a warning.

class Foobar
  def initialize(baz)
    @baz = "string"
  end
end
$ bundle exec steep check
# Type checking files:

.F

app/app.rb:3:4: [error] Cannot assign a value of type `::String` to a variable of type `::Integer`
│   ::String <: ::Integer
│     ::Object <: ::Integer
│       ::BasicObject <: ::Integer
│
│ Diagnostic ID: Ruby::IncompatibleAssignment
│
└     @baz = "string"
      ~~~~~~~~~~~~~~~

Detected 1 problem from 1 file

I checked the type of Integer#to_s using rbs method command:

$ bundle exec rbs -Isig method Integer to_s
::Integer#to_s
  defined_in: ::ActiveSupport::NumericWithFormat
  implementation: ::ActiveSupport::NumericWithFormat
  accessibility: public
  types:
      (?untyped? format, ?untyped? options) -> untyped   at /Users/tkomiya/work/tmp/tmp/.gem_rbs_collection/activesupport/7.0/activesupport-generated.rbs:4169:14...4169:62

Could you check the gem is installed on your project? If installed, it's not a bug of Steep.

tk0miya added a commit to tk0miya/gem_rbs_collection that referenced this issue Feb 12, 2025
…ithFormat#to_s

`#to_s` methods should return String object.

Additionally, I moved the definitions to activesupport-6.0.rbs, not
activesupport.rbs because `#to_s` overrides ware marked as deprecated
since v7.0, and removed since v7.1.

refs:

* rails/rails#43772
* rails/rails@e420c33
* soutaro/steep#1478
@tk0miya
Copy link
Contributor

tk0miya commented Feb 12, 2025

I posted the fix for the type of activesupport gem to the gem_rbs_collection repo. I suppose it will fix your problem. Please check it.

tk0miya added a commit to tk0miya/gem_rbs_collection that referenced this issue Feb 13, 2025
…ithFormat#to_s

`#to_s` methods should return String object.

Additionally, I moved the definitions to activesupport-6.0.rbs, not
activesupport.rbs because `#to_s` overrides ware marked as deprecated
since v7.0, and removed since v7.1.

refs:

* rails/rails#43772
* rails/rails@e420c33
* soutaro/steep#1478
tk0miya added a commit to tk0miya/gem_rbs_collection that referenced this issue Feb 13, 2025
…ithFormat#to_s

`#to_s` methods should return String object.

Additionally, I moved the definitions to activesupport-6.0.rbs, not
activesupport.rbs because `#to_s` overrides ware marked as deprecated
since v7.0, and removed since v7.1.

refs:

* rails/rails#43772
* rails/rails@e420c33
* soutaro/steep#1478
github-actions bot pushed a commit to ruby/gem_rbs_collection that referenced this issue Feb 13, 2025
…ithFormat#to_s (#791)

`#to_s` methods should return String object.

Additionally, I moved the definitions to activesupport-6.0.rbs, not
activesupport.rbs because `#to_s` overrides ware marked as deprecated
since v7.0, and removed since v7.1.

refs:

* rails/rails#43772
* rails/rails@e420c33
* soutaro/steep#1478
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

No branches or pull requests

2 participants