From 1b2708b123038802740e58672e459fb6b575354c Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 13 Feb 2024 17:44:11 +0100 Subject: [PATCH] [ruby/prism] Remove attr_writer's for ParseResult#start_line and #offsets * As the user should not set these. * Use #instance_variable_set/rb_iv_set() instead internally. https://github.com/ruby/prism/commit/cace09fb8c --- lib/prism/parse_result.rb | 4 ++-- prism/templates/ext/prism/api_node.c.erb | 4 ++-- prism/templates/lib/prism/serialize.rb.erb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb index 785d2acf35..a3f588bb20 100644 --- a/lib/prism/parse_result.rb +++ b/lib/prism/parse_result.rb @@ -9,10 +9,10 @@ module Prism attr_reader :source # The line number where this source starts. - attr_accessor :start_line + attr_reader :start_line # The list of newline byte offsets in the source code. - attr_accessor :offsets + attr_reader :offsets # Create a new source object with the given source code. def initialize(source) diff --git a/prism/templates/ext/prism/api_node.c.erb b/prism/templates/ext/prism/api_node.c.erb index 8bcd4f402b..b4a9d28cf7 100644 --- a/prism/templates/ext/prism/api_node.c.erb +++ b/prism/templates/ext/prism/api_node.c.erb @@ -49,13 +49,13 @@ pm_source_new(pm_parser_t *parser, rb_encoding *encoding) { void pm_source_init(VALUE source, pm_parser_t *parser) { - rb_funcall(source, rb_intern("start_line="), 1, LONG2NUM(parser->start_line)); + rb_iv_set(source, "@start_line", LONG2NUM(parser->start_line)); VALUE offsets = rb_ary_new_capa(parser->newline_list.size); for (size_t index = 0; index < parser->newline_list.size; index++) { rb_ary_push(offsets, ULONG2NUM(parser->newline_list.offsets[index])); } - rb_funcall(source, rb_intern("offsets="), 1, offsets); + rb_iv_set(source, "@offsets", offsets); } typedef struct pm_node_stack_node { diff --git a/prism/templates/lib/prism/serialize.rb.erb b/prism/templates/lib/prism/serialize.rb.erb index 500a980341..3ab92335d5 100644 --- a/prism/templates/lib/prism/serialize.rb.erb +++ b/prism/templates/lib/prism/serialize.rb.erb @@ -79,11 +79,11 @@ module Prism end def load_start_line - source.start_line = load_varsint + source.instance_variable_set :@start_line, load_varsint end def load_line_offsets - source.offsets = load_varuint.times.map { load_varuint } + source.instance_variable_set :@offsets, load_varuint.times.map { load_varuint } end def load_comments