soutaro / steep

Static type checker for Ruby
MIT License
1.37k stars 83 forks source link

Unexpected error: #<RuntimeError: Unknown name for build_instance: ::Foo> #660

Open ksss opened 1 year ago

ksss commented 1 year ago

I'm not sure if this is rbs issue or steep issue, but I voted for this one because it is reproduced when both annotations and if statements are used.

$ cat sample.rb
# @type var foo: Foo
foo = Foo.new
if foo.bar
end
$ cat Steepfile
target :sample do
  check "sample.rb"
end
$ bundle exec steep check ``` $ bundle exec steep check # Type checking files: ............................................................................[Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] Unexpected error: # [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.7.0/lib/rbs/definition_builder.rb:139:in `block in build_instance' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.7.0/lib/rbs/definition_builder.rb:860:in `try_cache' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.7.0/lib/rbs/definition_builder.rb:138:in `build_instance' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/interface/builder.rb:271:in `object_shape' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/interface/builder.rb:138:in `block in shape' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/interface/builder.rb:117:in `fetch_cache' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/interface/builder.rb:122:in `shape' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:3074:in `calculate_interface' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:3036:in `type_send' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:813:in `block (2 levels) in synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] :148:in `yield_self' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:802:in `block in synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `block in tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:37:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:682:in `synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:1806:in `block (2 levels) in synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] :148:in `yield_self' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:1803:in `block in synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `block in tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:37:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:682:in `synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:701:in `block (2 levels) in synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] :148:in `yield_self' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:686:in `block in synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `block in tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:37:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/type_construction.rb:682:in `synthesize' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/services/type_check_service.rb:393:in `type_check' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/services/type_check_service.rb:329:in `block in type_check_file' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `block in tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:37:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/services/type_check_service.rb:327:in `type_check_file' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/services/type_check_service.rb:283:in `block (2 levels) in typecheck_source' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep.rb:175:in `measure' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/services/type_check_service.rb:277:in `block in typecheck_source' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `block in tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:37:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/services/type_check_service.rb:276:in `typecheck_source' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/server/type_check_worker.rb:184:in `handle_job' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/server/base_worker.rb:54:in `block (2 levels) in run' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `block in tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:37:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/tagged_logging.rb:99:in `tagged' [Steep 1.2.0] [typecheck:typecheck@0] [background] [#typecheck_source(path=sample.rb)] [#type_check_file(sample.rb@sample)] [synthesize:(2:1)] [synthesize:(3:1)] [synthesize:(3:4)] /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/bundler/gems/steep-3cf26497c92c/lib/steep/server/base_worker.rb:44:in `block in run' F.... sample.rb:2:6: [warning] Cannot find the declaration of constant: `Foo` │ Diagnostic ID: Ruby::UnknownConstant │ └ foo = Foo.new ~~~ sample.rb:3:3: [error] UnexpectedError: Unknown name for build_instance: ::Foo │ Diagnostic ID: Ruby::UnexpectedError │ └ if foo.bar ~~~~~~~ Detected 2 problems from 1 file ```

steep: 3cf26497c92c8659e76ea970102dff37f2318da3 (current master) rbs: v2.7.0

$ ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [arm64-darwin21]
soutaro commented 1 year ago

Interesting.

If the @type var annotation is not given, the type of foo is untyped, which is inferred by the right hand side. But, this is ::Foo while Steep doesn't know what the type is exactly!