Skip to content

Commit

Permalink
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/compiler/crystal/semantic/exception.cr
Original file line number Diff line number Diff line change
@@ -176,8 +176,17 @@ module Crystal
has_trace = @trace.any?(&.location)
nil_reason = @nil_reason

if !@show && (has_trace || nil_reason)
io.print "Rerun with --error-trace to show a complete error trace."
if !@show
if nil_reason
print_nil_reason(nil_reason, io)
if has_trace || nil_reason.try(&.nodes)
io.puts
io.puts
end
end
if has_trace || nil_reason.try(&.nodes)
io.print "Rerun with --error-trace to show a complete error trace."
end
return
end

@@ -199,19 +208,23 @@ module Crystal
io.puts ("=" * 80)
io.puts

print_nil_reason(nil_reason, io)

if nil_reason_nodes = nil_reason.nodes
nil_reason_nodes.each do |node|
print_with_location node, io
end
end
end

def print_nil_reason(nil_reason, io)
io << colorize("Error: ").bold
case nil_reason.reason
when :used_before_initialized
io << colorize("instance variable '#{nil_reason.name}' was used before it was initialized in one of the 'initialize' methods, rendering it nilable").bold
when :used_self_before_initialized
io << colorize("'self' was used before initializing instance variable '#{nil_reason.name}', rendering it nilable").bold
end

if nil_reason_nodes = nil_reason.nodes
nil_reason_nodes.each do |node|
print_with_location node, io
end
end
end

def print_with_location(node, io)

0 comments on commit 9bd2294

Please sign in to comment.