Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unexpected error #411

Merged
merged 1 commit into from
Aug 22, 2021
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
34 changes: 34 additions & 0 deletions lib/steep/diagnostic/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,34 @@ def header_line
end
end

class MixinClassError < Base
attr_reader :member
attr_reader :type_name

def initialize(location:, member:, type_name:)
super(location: location)
@member = member
@type_name = type_name
end

def header_line
"Cannot #{mixin_name} a class `#{member.name}` in the definition of `#{type_name}`"
end

private

def mixin_name
case member
when RBS::AST::Members::Prepend
"prepend"
when RBS::AST::Members::Include
"include"
when RBS::AST::Members::Extend
"extend"
end
end
end

class UnexpectedError < Base
attr_reader :message

Expand Down Expand Up @@ -365,6 +393,12 @@ def self.from_rbs_error(error, factory:)
param: error.param,
location: error.location
)
when RBS::MixinClassError
Diagnostic::Signature::MixinClassError.new(
location: error.location,
type_name: error.type_name,
member: error.member,
)
else
raise error
end
Expand Down
6 changes: 6 additions & 0 deletions smoke/diagnostics-rbs/mixin-class-error.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Foo
end

class Bar
include Foo
end
12 changes: 12 additions & 0 deletions smoke/diagnostics-rbs/test_expectations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,15 @@
severity: ERROR
message: Cannot find type `ZZZ`
code: RBS::UnknownTypeName
- file: mixin-class-error.rbs
diagnostics:
- range:
start:
line: 5
character: 2
end:
line: 5
character: 13
severity: ERROR
message: Cannot include a class `::Foo` in the definition of `::Bar`
code: RBS::MixinClassError