ruby / typeprof

An experimental type-level Ruby interpreter for testing and understanding Ruby code
MIT License
755 stars 84 forks source link

[warning] already initialized constant Foo::A #59

Open ulcttku opened 2 years ago

ulcttku commented 2 years ago

The warning [warning] already initialized constant Foo::A is displayed. When a class with constants exists in an RBS file that has already been created.

Ruby TypeProf Playground https://mame.github.io/typeprof-playground/#rb=class+Foo%0A++A+%3D+1%0Aend%0A&rbs=class+Foo%0A++A%3A+Integer%0Aend

Ruby

class Foo
  A = 1
end

RBS

class Foo
  A: Integer
end

Output

# TypeProf 0.15.0

# Errors
test.rb:2: [warning] already initialized constant Foo::A

# Classes
class Foo
  A: Integer
end

## Version info:
##   * Ruby: 3.0.0
##   * RBS: 1.3.1
##   * TypeProf: 0.15.0
mame commented 2 years ago

Thank you for your report and sorry for my late action! I've added a tentative fix to suppress the warning.

I'd like to keep this ticket open because there is still room to improve. If an inconsistent type is assigned to a constant that is already defined in RBS, currently it is merged but it should be warned. https://github.com/ruby/typeprof/commit/4804e1e212c37f14893724a876e0f427159afca4#diff-8ac76f2b46ac161391ac2190da7192f7c9b6263037c547efa93ecdfd47a6f660R2