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

Update rbs #1443

Merged
merged 8 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PATH
logger (>= 1.3.0)
parser (>= 3.1)
rainbow (>= 2.2.2, < 4.0)
rbs (~> 3.7.0)
rbs (~> 3.8)
securerandom (>= 0.1)
strscan (>= 1.0.0)
terminal-table (>= 2, < 4)
Expand Down Expand Up @@ -79,7 +79,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rbs (3.7.0)
rbs (3.8.0)
logger
rdoc (6.10.0)
psych (>= 4.0.0)
Expand Down
2 changes: 2 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "fileutils"

D = Steep::Diagnostic

FileUtils.mkpath("tmp")
Expand Down
3 changes: 1 addition & 2 deletions gemfile_steep/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ GEM
connection_pool (2.4.1)
csv (3.3.2)
drb (2.2.1)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
ffi (1.17.0)
fileutils (1.7.3)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
Expand Down
4 changes: 2 additions & 2 deletions lib/steep/annotation_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def parse(src, location:)
name = match[:name] or raise
type = parse_type(match, location: location)

AST::Annotation::ConstType.new(name: TypeName(name), type: type, location: location)
AST::Annotation::ConstType.new(name: RBS::TypeName.parse(name), type: type, location: location)
end

when keyword_subject_type("ivar", IVAR_NAME)
Expand Down Expand Up @@ -184,7 +184,7 @@ def parse(src, location:)
when /@implements\s+(?<name>#{CONST_NAME})#{TYPE_PARAMS}$/
Regexp.last_match.yield_self do |match|
match or raise
type_name = TypeName(match[:name] || raise)
type_name = RBS::TypeName.parse(match[:name] || raise)
params = match[:params]&.yield_self {|params| params.split(/,/).map {|param| param.strip.to_sym } } || []

name = AST::Annotation::Implements::Module.new(name: type_name, args: params)
Expand Down
2 changes: 1 addition & 1 deletion lib/steep/ast/builtin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Type
attr_reader :arity

def initialize(module_name, arity: 0)
@module_name = TypeName(module_name)
@module_name = RBS::TypeName.parse(module_name)
@arity = arity
end

Expand Down
4 changes: 2 additions & 2 deletions lib/steep/interface/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def replace_primitive_method(method_name, method_def, method_type)
RBS::BuiltinNames::Symbol.name,
RBS::BuiltinNames::TrueClass.name,
RBS::BuiltinNames::FalseClass.name,
TypeName("::NilClass")
RBS::TypeName.parse("::NilClass")
# Value based type-case works on literal types which is available for String, Integer, Symbol, TrueClass, FalseClass, and NilClass
return method_type.with(
type: method_type.type.with(
Expand Down Expand Up @@ -828,7 +828,7 @@ def replace_kernel_class(method_name, method_def, method_type)

def add_implicitly_returns_nil(annotations, method_type)
return method_type unless implicitly_returns_nil

if annotations.find { _1.string == "implicitly-returns-nil" }
return_type = method_type.type.return_type
method_type = method_type.with(
Expand Down
2 changes: 1 addition & 1 deletion lib/steep/interface/type_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def self.rename(params, conflicting_names = params.map(&:name), new_names = conf
end

def to_s
buf = ""
buf = +""

if unchecked
buf << "unchecked "
Expand Down
4 changes: 2 additions & 2 deletions lib/steep/method_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def MethodName(string)
type_name, method_name = string.split(/#/, 2)
type_name or raise
method_name or raise
InstanceMethodName.new(type_name: TypeName(type_name), method_name: method_name.to_sym)
InstanceMethodName.new(type_name: RBS::TypeName.parse(type_name), method_name: method_name.to_sym)
when /\./
type_name, method_name = string.split(/\./, 2)
type_name or raise
method_name or raise
SingletonMethodName.new(type_name: TypeName(type_name), method_name: method_name.to_sym)
SingletonMethodName.new(type_name: RBS::TypeName.parse(type_name), method_name: method_name.to_sym)
else
raise "Unexpected method name: #{string}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/steep/server/lsp_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def name_and_params(name, params)
"#{name}"
else
ps = params.each.map do |param|
s = ""
s = +""
if param.unchecked?
s << "unchecked "
end
Expand Down
4 changes: 2 additions & 2 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1385,10 +1385,10 @@ def synthesize(node, hint: nil, condition: false)
add_typing(node, type: AST::Builtin::Float.instance_type)

when :rational
add_typing(node, type: AST::Types::Name::Instance.new(name: TypeName("::Rational"), args: []))
add_typing(node, type: AST::Types::Name::Instance.new(name: RBS::TypeName.parse("::Rational"), args: []))

when :complex
add_typing(node, type: AST::Types::Name::Instance.new(name: TypeName("::Complex"), args: []))
add_typing(node, type: AST::Types::Name::Instance.new(name: RBS::TypeName.parse("::Complex"), args: []))

when :nil
add_typing(node, type: AST::Builtin.nil_type)
Expand Down
2 changes: 1 addition & 1 deletion steep.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
spec.add_runtime_dependency "listen", "~> 3.0"
spec.add_runtime_dependency "language_server-protocol", ">= 3.15", "< 4.0"
spec.add_runtime_dependency "rbs", "~> 3.7.0"
spec.add_runtime_dependency "rbs", "~> 3.8"
spec.add_runtime_dependency "concurrent-ruby", ">= 1.1.10"
spec.add_runtime_dependency "terminal-table", ">= 2", "< 4"
spec.add_runtime_dependency "securerandom", ">= 0.1"
Expand Down
14 changes: 7 additions & 7 deletions test/annotation_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def new_collection(current_module:, factory:)
annotations: [
Annotation::VarType.new(name: :x, type: parse_type("Object")),
Annotation::IvarType.new(name: :@y, type: parse_type("Object")),
Annotation::ConstType.new(name: TypeName("Object"), type: parse_type("singleton(Object)")),
Annotation::ConstType.new(name: RBS::TypeName.parse("Object"), type: parse_type("singleton(Object)")),
Annotation::MethodType.new(name: :foo, type: parse_method_type("() -> Object")),
Annotation::BlockType.new(type: parse_type("Object")),
Annotation::ReturnType.new(type: parse_type("Object")),
Annotation::SelfType.new(type: parse_type("String")),
Annotation::InstanceType.new(type: parse_type("String")),
Annotation::ModuleType.new(type: parse_type("String")),
Annotation::BreakType.new(type: parse_type("::Object")),
Annotation::Implements.new(name: Annotation::Implements::Module.new(name: TypeName("Object"), args: [])),
Annotation::Implements.new(name: Annotation::Implements::Module.new(name: RBS::TypeName.parse("Object"), args: [])),
Annotation::Dynamic.new(names: [
Annotation::Dynamic::Name.new(name: :foo, kind: :instance),
Annotation::Dynamic::Name.new(name: :bar, kind: :module),
Expand All @@ -46,16 +46,16 @@ class Person::Object

def test_types
with_factory RBIS do |factory|
annotations = new_collection(current_module: TypeName("::Person"), factory: factory)
annotations = new_collection(current_module: RBS::TypeName.parse("::Person"), factory: factory)

assert_equal parse_type("::Person::Object"), annotations.var_type(lvar: :x)
assert_nil annotations.var_type(lvar: :y)

assert_equal parse_type("::Person::Object"), annotations.var_type(ivar: :@y)
assert_nil annotations.var_type(ivar: :@x)

assert_equal parse_type("singleton(::Person::Object)"), annotations.var_type(const: TypeName("Object"))
assert_nil annotations.var_type(const: TypeName("::Object"))
assert_equal parse_type("singleton(::Person::Object)"), annotations.var_type(const: RBS::TypeName.parse("Object"))
assert_nil annotations.var_type(const: RBS::TypeName.parse("::Object"))

assert_equal "() -> ::Person::Object", annotations.method_type(:foo).to_s

Expand All @@ -70,7 +70,7 @@ def test_types

def test_dynamics
with_factory do |factory|
annotations = new_collection(current_module: TypeName("::Person"), factory: factory)
annotations = new_collection(current_module: RBS::TypeName.parse("::Person"), factory: factory)

assert_equal [:foo, :baz], annotations.instance_dynamics
assert_equal [:bar, :baz], annotations.module_dynamics
Expand All @@ -79,7 +79,7 @@ def test_dynamics

def test_merge_block_annotations
with_factory RBIS do |factory|
namespace = TypeName("::Person")
namespace = RBS::TypeName.parse("::Person")
current_annotations = new_collection(current_module: namespace, factory: factory)

block_annotations = Annotation::Collection.new(
Expand Down
10 changes: 5 additions & 5 deletions test/annotation_parsing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_const_type
with_factory do |factory|
annot = parse_annotation("@type const Foo::Bar::Baz: String", factory: factory)
assert_instance_of Annotation::ConstType, annot
assert_equal TypeName("Foo::Bar::Baz"), annot.name
assert_equal RBS::TypeName.parse("Foo::Bar::Baz"), annot.name
assert_equal parse_type("String", factory: factory), annot.type
end
end
Expand All @@ -85,7 +85,7 @@ def test_const_type2
with_factory do |factory|
annot = parse_annotation("@type const Foo: String", factory: factory)
assert_instance_of Annotation::ConstType, annot
assert_equal TypeName("Foo"), annot.name
assert_equal RBS::TypeName.parse("Foo"), annot.name
assert_equal parse_type("String", factory: factory), annot.type
end
end
Expand All @@ -94,7 +94,7 @@ def test_const_type3
with_factory do |factory|
annot = parse_annotation("@type const ::Foo: String", factory: factory)
assert_instance_of Annotation::ConstType, annot
assert_equal TypeName("::Foo"), annot.name
assert_equal RBS::TypeName.parse("::Foo"), annot.name
assert_equal parse_type("String", factory: factory), annot.type
end
end
Expand All @@ -119,7 +119,7 @@ def test_implements
with_factory do |factory|
annot = parse_annotation("@implements String", factory: factory)
assert_instance_of Annotation::Implements, annot
assert_equal TypeName("String"), annot.name.name
assert_equal RBS::TypeName.parse("String"), annot.name.name
assert_empty annot.name.args
end
end
Expand All @@ -128,7 +128,7 @@ def test_implement2
with_factory do |factory|
annot = parse_annotation("@implements Array[A]", factory: factory)
assert_instance_of Annotation::Implements, annot
assert_equal TypeName('Array'), annot.name.name
assert_equal RBS::TypeName.parse('Array'), annot.name.name
assert_equal [:A], annot.name.args
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/ast/node/type_application_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Bar
app = Steep::AST::Node::TypeApplication.parse(loc)

assert_equal "Bar", app.type_str
app.types([nil, TypeName("::Foo")], checker, []).tap do |types|
app.types([nil, RBS::TypeName.parse("::Foo")], checker, []).tap do |types|
assert_equal 1, types.size
assert_equal parse_type("::Foo::Bar"), types[0].value
assert_equal "Bar", types[0].location.source
Expand Down
2 changes: 1 addition & 1 deletion test/ast/node/type_assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Bar
assert_equal "Array[Bar]", assertion.type_str
assert_predicate assertion, :type_syntax?

type = assertion.type([nil, TypeName("::Foo")], checker, [])
type = assertion.type([nil, RBS::TypeName.parse("::Foo")], checker, [])
assert_equal parse_type("::Array[::Foo::Bar]"), type
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class Person
pid = spawn(*steep, "watch", "app/lib", out: w, chdir: current_dir.to_s)
w.close

output = ""
output = +""

begin
read_thread = Thread.new do
Expand Down Expand Up @@ -578,7 +578,7 @@ class Person
pid = spawn(*steep.push("watch", "app/models/person.rb"), out: w, chdir: current_dir.to_s)
w.close

output = ""
output = +""

begin
read_thread = Thread.new do
Expand Down
6 changes: 3 additions & 3 deletions test/completion_provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def test_on_steep_inline_comment
RUBY

provider.run(line: 1, column: 17).tap do |items|
assert_equal [TypeName("Array")], items.map(&:relative_type_name)
assert_equal [RBS::TypeName.parse("Array")], items.map(&:relative_type_name)
end
end
end
Expand All @@ -549,7 +549,7 @@ def test_on_steep_type_assertion
RUBY

provider.run(line: 1, column: 12).tap do |items|
assert_equal [TypeName("Array")], items.map(&:relative_type_name)
assert_equal [RBS::TypeName.parse("Array")], items.map(&:relative_type_name)
end
end
end
Expand All @@ -563,7 +563,7 @@ def test_on_steep_type_application
RUBY

provider.run(line: 1, column: 33).tap do |items|
assert_equal [TypeName("Array")], items.map(&:relative_type_name)
assert_equal [RBS::TypeName.parse("Array")], items.map(&:relative_type_name)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions test/constant_env_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ def with_constant_env(sigs = {}, context:)
end

def test_from_module
with_constant_env({ "foo.rbs" => <<-EOS }, context: [nil, TypeName("::A")]) do |env|
with_constant_env({ "foo.rbs" => <<-EOS }, context: [nil, RBS::TypeName.parse("::A")]) do |env|
module A end
module A::String end
EOS
assert_equal TypeName("::A::String"), env.resolve(:String)[1]
assert_equal TypeName("::String"), env.toplevel(:String)[1]
assert_equal RBS::TypeName.parse("::A::String"), env.resolve(:String)[1]
assert_equal RBS::TypeName.parse("::String"), env.toplevel(:String)[1]
end
end

def test_module_alias
with_constant_env({ "foo.rbs" => <<-EOS }, context: [nil, TypeName("::A")]) do |env|
with_constant_env({ "foo.rbs" => <<-EOS }, context: [nil, RBS::TypeName.parse("::A")]) do |env|
module A end
module B = A
EOS
assert_equal TypeName("::A"), env.resolve(:A)[1]
assert_equal TypeName("::B"), env.toplevel(:B)[1]
assert_equal RBS::TypeName.parse("::A"), env.resolve(:A)[1]
assert_equal RBS::TypeName.parse("::B"), env.toplevel(:B)[1]
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/constraints_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def test_variable_elimination
constraints.eliminate_variable(AST::Types::Intersection.build(types: [AST::Types::Var.new(name: :a),
AST::Types::Var.new(name: :b)]),
to: AST::Types::Bot.new)
assert_equal AST::Types::Name::Instance.new(name: TypeName("::String"), args: [AST::Types::Any.new]),
constraints.eliminate_variable(AST::Types::Name::Instance.new(name: TypeName("::String"),
assert_equal AST::Types::Name::Instance.new(name: RBS::TypeName.parse("::String"), args: [AST::Types::Any.new]),
constraints.eliminate_variable(AST::Types::Name::Instance.new(name: RBS::TypeName.parse("::String"),
args: [AST::Types::Var.new(name: :a)]),
to: AST::Types::Top.new)
end
Expand Down
Loading
Loading