-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add type checking with Sorbet #1148
base: master
Are you sure you want to change the base?
Conversation
this only works locally
Can be triggered by `sudo mv /usr/bin/systemctl{,.away}` Test: ```sh Y2DIR=library/systemd/src ruby -ryast -ryast2/systemd/target -e 'pp Yast2::Systemd::Target.get_default' ``` Before: /usr/share/YaST2/lib/yast2/systemd/target.rb:83:in `get_default': uninitialized constant #<Class:Yast2::Systemd::Target>::SystemctlError (NameError) After: /home/martin/svn/yast-yast2/library/systemd/src/lib/yast2/systemd/target.rb:84:in `get_default': Systemctl command failed: #<OpenStruct exit=127, stderr="sh: /usr/bin/systemctl: No such file or directory\n", stdout="", command=" LANG=C TERM=dumb COLUMNS=1024 /usr/bin/systemctl --plain --full --no-legend --no-pager --no-ask-password get-default"> (Yast2::Systemctl::Error) Found by sorbet
after SystemcltError bugfix and srb rbi todo to fix module/class mismatch
class A < described_class is too dynamic for sorbet.
declaring a constant in one block and using it in another is legal Ruby but confuses sorbet. move them a level up.
(git merge -s ours) At first I tried to do things the normal way: take the old 2019 sorbet branch and merge master into it. That meant merge conflicts EVERYWHERE because sorbet added "# typed" at the top while master deleted "encoding" at the top. Scratch that. In 2021 I re-did the earlier work on top of master and then formally merged the old branch to signify it does the same thing.
You may wonder why we have to do this because it is pretty obvious that a StageClass.new is of type StageClass. Well this inference works for a variable (stage = StageClass.new) but not for a Stage constant.
otherwise bundler will find a different bundler and stop
In https://github.com/yast/yast-yast2/compare/sorbet-typebug-demo?expand=1 I have added a bug (0e56df4) to show how a detected bug looks like. |
@@ -78,6 +80,8 @@ Requires: augeas-lenses | |||
# For converting to/from punycode strings | |||
Requires: sysconfig >= 0.80.0 | |||
Requires: rubygem(%{rb_default_ruby_abi}:simpleidn) | |||
# Type checking | |||
BuildRequires: rubygem(%{rb_default_ruby_abi}:sorbet-runtime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you really want to do type checking during rpm build?
module Yast::ProductProfileClass::YaPI::SubscriptionTools; end | ||
module Yast::Proxy; end | ||
module Yast::SuSEFirewalldClass::FirewallCMDError; end | ||
module Yast::XMLClass::Nokogiri; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks wrong as nokogiri should be autogenerated, not?
with new sigs in yast2-ruby-bindings these files can be typechecked after adding sigs Builtins: foreach regexpmatch, WFM::CallFunction
IMHO this is a design bug in Ruby copied into Sorbet. A Boolean class should exist in Ruby, or Sorbet should infer it, without us having to declare it with T.let Without this: ``` ./library/packages/src/modules/PackageKit.rb:52: Changing the type of a variable in a loop is not permitted https://srb.help/7001 52 | ret = true if Builtins.regexpmatch(line, "boolean.*true") ^^^^ Existing variable has type: FalseClass Attempting to change type to: TrueClass ```
(Part of SUSE Hackweek: https://hackweek.suse.com/20/projects/type-check-yast-with-sorbet)
See yast/yast-ruby-bindings#273 for context