lib/rbs/errors.rb in rbs-1.0.0.pre vs lib/rbs/errors.rb in rbs-1.0.0.pre2
- old
+ new
@@ -33,38 +33,10 @@
raise new(type_name: type_name, args: args, params: params, location: location)
end
end
end
- class InvalidExtensionParameterError < StandardError
- attr_reader :type_name
- attr_reader :extension_name
- attr_reader :location
- attr_reader :extension_params
- attr_reader :class_params
-
- def initialize(type_name:, extension_name:, extension_params:, class_params:, location:)
- @type_name = type_name
- @extension_name = extension_name
- @extension_params = extension_params
- @class_params = class_params
- @location = location
-
- super "#{Location.to_string location}: Expected #{class_params.size} parameters to #{type_name} (#{extension_name}) but has #{extension_params.size} parameters"
- end
-
- def self.check!(type_name:, extension_name:, extension_params:, class_params:, location:)
- unless extension_params.size == class_params.size
- raise new(type_name: type_name,
- extension_name: extension_name,
- extension_params: extension_params,
- class_params: class_params,
- location: location)
- end
- end
- end
-
class RecursiveAncestorError < StandardError
attr_reader :ancestors
attr_reader :location
def initialize(ancestors:, location:)
@@ -160,10 +132,12 @@
dic = case
when type_name.class?
env.class_decls
when type_name.interface?
env.interface_decls
+ else
+ raise
end
dic.key?(type_name) or raise new(type_name: type_name, location: self_type.location)
end
end
@@ -187,10 +161,12 @@
dic = case
when type_name.class?
env.class_decls
when type_name.interface?
env.interface_decls
+ else
+ raise
end
dic.key?(type_name) or raise new(type_name: type_name, member: member)
end
end
@@ -203,11 +179,15 @@
def initialize(type:, method_name:, members:)
@type = type
@method_name = method_name
@members = members
- super "#{Location.to_string location}: #{qualified_method_name} has duplicated definitions"
+ message = "#{Location.to_string location}: #{qualified_method_name} has duplicated definitions"
+ if members.size > 1
+ message << " in #{other_locations.map { |loc| Location.to_string loc }.join(', ')}"
+ end
+ super message
end
def qualified_method_name
case type
when Types::ClassSingleton
@@ -218,15 +198,17 @@
end
def location
members[0].location
end
+
+ def other_locations
+ members.drop(1).map(&:location)
+ end
end
class DuplicatedInterfaceMethodDefinitionError < StandardError
- include MethodNameHelper
-
attr_reader :type
attr_reader :method_name
attr_reader :member
def initialize(type:, method_name:, member:)
@@ -263,40 +245,17 @@
class SuperclassMismatchError < StandardError
attr_reader :name
attr_reader :entry
- def initialize(name:, super_classes:, entry:)
+ def initialize(name:, entry:)
@name = name
@entry = entry
super "#{Location.to_string entry.primary.decl.location}: Superclass mismatch: #{name}"
end
end
- class InconsistentMethodVisibilityError < StandardError
- attr_reader :type_name
- attr_reader :method_name
- attr_reader :kind
- attr_reader :member_pairs
-
- def initialize(type_name:, method_name:, kind:, member_pairs:)
- @type_name = type_name
- @method_name = method_name
- @kind = kind
- @member_pairs = member_pairs
-
- delimiter = case kind
- when :instance
- "#"
- when :singleton
- "."
- end
-
- super "#{Location.to_string member_pairs[0][0].location}: Inconsistent method visibility: #{type_name}#{delimiter}#{method_name}"
- end
- end
-
class InvalidOverloadMethodError < StandardError
attr_reader :type_name
attr_reader :method_name
attr_reader :kind
attr_reader :members
@@ -335,11 +294,12 @@
def initialize(name, *decls)
@name = name
@decls = decls
- super "#{Location.to_string decls.last.location}: Duplicated declaration: #{name}"
+ last_decl = decls.last or raise
+ super "#{Location.to_string last_decl.location}: Duplicated declaration: #{name}"
end
end
class InvalidVarianceAnnotationError < StandardError
attr_reader :type_name
@@ -365,9 +325,11 @@
super "#{Location.to_string location}: Recursive aliases in #{type}: #{defs.map(&:name).join(", ")}"
end
def location
- defs[0].original.location
+ first_def = defs.first or raise
+ original = first_def.original or raise
+ original.location
end
end
end