From 7e3ea58b3303a21ce679717a01c57e0e0850a4c6 Mon Sep 17 00:00:00 2001 From: rhiroe Date: Mon, 27 Apr 2026 06:16:48 +0000 Subject: [PATCH] Fix NoMethodError when RBS file contains class/module alias decl `AST.create_rbs_decl` has an empty `when RBS::AST::Declarations::AliasDecl` branch that returns nil, but `AST.parse_rbs` did not `.compact` the result, so the nil reached `decls.each {|decl| decl.define(@genv) }` and crashed the LSP server. The two other callers of `create_rbs_decl` / `create_rbs_member` already use `.compact`; this aligns `parse_rbs` with the same pattern. --- lib/typeprof/core/ast.rb | 2 +- scenario/rbs/class-module-alias.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 scenario/rbs/class-module-alias.rb diff --git a/lib/typeprof/core/ast.rb b/lib/typeprof/core/ast.rb index 43a43945..dd2abef3 100644 --- a/lib/typeprof/core/ast.rb +++ b/lib/typeprof/core/ast.rb @@ -423,7 +423,7 @@ def self.parse_rbs(path, src) raw_decls.map do |raw_decl| AST.create_rbs_decl(raw_decl, lenv) - end + end.compact end def self.create_rbs_decl(raw_decl, lenv) diff --git a/scenario/rbs/class-module-alias.rb b/scenario/rbs/class-module-alias.rb new file mode 100644 index 00000000..5dfbb07a --- /dev/null +++ b/scenario/rbs/class-module-alias.rb @@ -0,0 +1,21 @@ +## update: test.rbs +class Foo + def foo: () -> Integer +end +class Bar = Foo +module M + def m: () -> String +end +module N = M + +## update: test.rb +def test1 + Foo.new.foo +end + +## assert: test.rb +class Object + def test1: -> Integer +end + +## diagnostics: test.rb