From dc315cac89eb12a09d0a7dc4acf1f24b4d3e30a2 Mon Sep 17 00:00:00 2001 From: ksss Date: Mon, 19 Oct 2026 14:51:56 +0900 Subject: [PATCH] Write annotations of constant, global, and class/module alias decls `RBS::Writer#write_decl` did not call `write_annotation` for `Constant`, `Global`, `ClassAlias`, and `ModuleAlias`, so `%a{...}` on those declarations disappeared from the output. The annotations were added to these AST nodes in 6f8d0f34, 1bc9bb4b, and 075d27c8, but the writer was not updated. Co-Authored-By: Claude Opus 5.5 --- lib/rbs/writer.rb | 4 ++++ test/rbs/writer_test.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/rbs/writer.rb b/lib/rbs/writer.rb index 4d2a1d0d21..89f4f9d6d0 100644 --- a/lib/rbs/writer.rb +++ b/lib/rbs/writer.rb @@ -159,10 +159,12 @@ def write_decl(decl) puts "end" when AST::Declarations::Constant write_comment decl.comment + write_annotation decl.annotations puts "#{decl.name}: #{decl.type}" when AST::Declarations::Global write_comment decl.comment + write_annotation decl.annotations puts "#{decl.name}: #{decl.type}" when AST::Declarations::TypeAlias @@ -174,12 +176,14 @@ def write_decl(decl) when AST::Declarations::ClassAlias write_comment decl.comment + write_annotation decl.annotations write_loc_source(decl) { puts "class #{decl.new_name} = #{decl.old_name}" } when AST::Declarations::ModuleAlias write_comment decl.comment + write_annotation decl.annotations write_loc_source(decl) { puts "module #{decl.new_name} = #{decl.old_name}" } diff --git a/test/rbs/writer_test.rb b/test/rbs/writer_test.rb index 44b4c3570d..225f1905ca 100644 --- a/test/rbs/writer_test.rb +++ b/test/rbs/writer_test.rb @@ -41,6 +41,37 @@ module C = D SIG end + def test_annotated_decl + assert_writer <<-SIG +%a{deprecated} +FOO: Integer + +%a{deprecated} +$foo: Integer + +# Alias of B. +%a{deprecated} +class A = B + +# Alias of D. +%a{deprecated} +module C = D + +module Foo + %a{deprecated} + FOO: Integer + + # Alias of B. + %a{deprecated} + class A = B + + # Alias of D. + %a{deprecated} + module C = D +end + SIG + end + def test_class_decl assert_writer <<-SIG class Foo::Bar[X] < Array[String]