diff --git a/lib/prism/node_ext.rb b/lib/prism/node_ext.rb index cdc4b2bf08..aa6a18cf29 100644 --- a/lib/prism/node_ext.rb +++ b/lib/prism/node_ext.rb @@ -5,10 +5,13 @@ module Prism class Node def deprecated(*replacements) # :nodoc: + location = caller_locations(1, 1) + location = location[0].label if location suggest = replacements.map { |replacement| "#{self.class}##{replacement}" } + warn(<<~MSG, category: :deprecated) - [deprecation]: #{self.class}##{caller_locations(1, 1)[0].label} is deprecated \ - and will be removed in the next major version. Use #{suggest.join("/")} instead. + [deprecation]: #{self.class}##{location} is deprecated and will be \ + removed in the next major version. Use #{suggest.join("/")} instead. #{(caller(1, 3) || []).join("\n")} MSG end @@ -261,9 +264,10 @@ module Prism end posts.each do |param| - if param.is_a?(MultiTargetNode) + case param + when MultiTargetNode names << [:req] - elsif param.is_a?(NoKeywordsParameterNode) + when NoKeywordsParameterNode, KeywordRestParameterNode, ForwardingParameterNode # Invalid syntax, e.g. "def f(**nil, ...)" moves the NoKeywordsParameterNode to posts raise "Invalid syntax" else diff --git a/lib/prism/parse_result/newlines.rb b/lib/prism/parse_result/newlines.rb index cc1343dfda..808a129a6b 100644 --- a/lib/prism/parse_result/newlines.rb +++ b/lib/prism/parse_result/newlines.rb @@ -25,6 +25,7 @@ module Prism class Newlines < Visitor # Create a new Newlines visitor with the given newline offsets. def initialize(lines) + # @type var lines: Integer @lines = Array.new(1 + lines, false) end