Skip to content

Commit ea7e400

Browse files
committed
Translation::Parser should process warnings, not just errors
1 parent dc9e003 commit ea7e400

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/prism/translation/parser.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class Diagnostic < ::Parser::Diagnostic
1717
attr_reader :message
1818

1919
# Initialize a new diagnostic with the given message and location.
20-
def initialize(message, location)
20+
def initialize(message, level, location)
2121
@message = message
22-
super(:error, :prism_error, {}, location, [])
22+
super(level, :prism_error, {}, location, [])
2323
end
2424
end
2525

@@ -113,7 +113,13 @@ def unwrap(result, offset_cache)
113113
next unless valid_error?(error)
114114

115115
location = build_range(error.location, offset_cache)
116-
diagnostics.process(Diagnostic.new(error.message, location))
116+
diagnostics.process(Diagnostic.new(error.message, :error, location))
117+
end
118+
result.warnings.each do |warning|
119+
next unless valid_error?(warning)
120+
121+
location = build_range(warning.location, offset_cache)
122+
diagnostics.process(Diagnostic.new(warning.message, :warning, location))
117123
end
118124

119125
result

test/prism/parser_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ class ParserTest < TestCase
9494
end
9595
end
9696

97+
def test_warnings
98+
buffer = Parser::Source::Buffer.new("inline ruby with warning", 1)
99+
buffer.source = "do_something *array"
100+
101+
parser = Prism::Translation::Parser.new
102+
parser.diagnostics.all_errors_are_fatal = false
103+
warning = nil
104+
parser.diagnostics.consumer = ->(received) { warning = received }
105+
parser.parse(buffer)
106+
assert_equal :warning, warning.level
107+
assert_includes warning.message, "has been interpreted as"
108+
end
109+
97110
private
98111

99112
def assert_equal_parses(filepath, compare_tokens: true)

0 commit comments

Comments
 (0)