Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rbs/definition_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,11 @@ def validate_variable(var)
case l.source
when AST::Members::InstanceVariable
if r.source.instance_of?(AST::Members::InstanceVariable) && l.declared_in == r.declared_in
raise InstanceVariableDuplicationError.new(member: l.source)
raise InstanceVariableDuplicationError.new(type_name: l.declared_in, variable_name: l.source.name, location: l.source.location)
end
when AST::Members::ClassInstanceVariable
if r.source.instance_of?(AST::Members::ClassInstanceVariable) && l.declared_in == r.declared_in
raise ClassInstanceVariableDuplicationError.new(member: l.source)
raise ClassInstanceVariableDuplicationError.new(type_name: l.declared_in, variable_name: l.source.name, location: l.source.location)
end
end
end
Expand Down
19 changes: 10 additions & 9 deletions lib/rbs/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,24 +325,25 @@ def type_name
class VariableDuplicationError < DefinitionError
include DetailedMessageable

attr_reader :member

def initialize(member:)
@member = member
attr_reader :type_name
attr_reader :variable_name
attr_reader :location

super "#{Location.to_string location}: Duplicated variable name #{member.name}"
end
def initialize(type_name:, variable_name:, location:)
@type_name = type_name
@variable_name = variable_name
@location = location

def location
loc = @member.location or raise
loc[:name]
super "#{Location.to_string location}: Duplicated #{kind} variable name `#{variable_name}` in `#{type_name}`"
end
end

class InstanceVariableDuplicationError < VariableDuplicationError
def kind = 'instance'
end

class ClassInstanceVariableDuplicationError < VariableDuplicationError
def kind = 'class instance'
end

class UnknownMethodAliasError < DefinitionError
Expand Down
11 changes: 7 additions & 4 deletions sig/errors.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,20 @@ module RBS
class VariableDuplicationError < DefinitionError
include DetailedMessageable

attr_reader member: AST::Members::Var

def initialize: (member: AST::Members::Var) -> void
attr_reader type_name: TypeName
attr_reader variable_name: Symbol
attr_reader location: Location[untyped, untyped]?

def location: () -> Location[bot, bot]
def initialize: (type_name: TypeName, variable_name: Symbol, location: Location[untyped, untyped]?) -> void
def kind: () -> String
end

class InstanceVariableDuplicationError < VariableDuplicationError
def kind: () -> String
end

class ClassInstanceVariableDuplicationError < VariableDuplicationError
def kind: () -> String
end

# The `alias` member declares an alias from unknown method
Expand Down