Skip to content

Commit

Permalink
Return nil if no source is found
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabigeek committed Mar 2, 2024
1 parent d2b3c81 commit a4dd7b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
18 changes: 14 additions & 4 deletions spec/ruby/core/exception/syntax_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@

ruby_version_is "3.2" do
describe "SyntaxError#path" do
it "returns the file path provided to eval" do
expected = 'speccing.rb'
-> {
eval('if true', TOPLEVEL_BINDING, expected)
}.should raise_error(SyntaxError) { |e|
e.path.should == expected
}
end

it "returns the file path that raised an exception" do
expected_path = File.expand_path(
"fixtures/syntax_error.rb",
File.dirname(__FILE__)
).to_s
expected_path = fixture(__FILE__, 'syntax_error.rb')
-> {
require_relative 'fixtures/syntax_error'
}.should raise_error(SyntaxError) {|e| e.path.should == expected_path }
end

it "returns nil when constructed directly" do
SyntaxError.new.path.should == nil
end
end
end
11 changes: 0 additions & 11 deletions spec/ruby/core/kernel/eval_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,6 @@
}
end

ruby_version_is "3.2" do
it "includes path in syntax error" do
expected = 'speccing.rb'
-> {
eval('if true', TOPLEVEL_BINDING, expected)
}.should raise_error(SyntaxError) { |e|
e.path.should == expected
}
end
end

it "evaluates string with given filename and negative linenumber" do
expected_file = 'speccing.rb'
-> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.Source;

import static org.truffleruby.language.RubyBaseNode.nil;

@CoreModule(value = "SyntaxError", isClass = true)
public abstract class SyntaxErrorNodes {

Expand All @@ -46,9 +48,9 @@ public abstract static class PathNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization
RubyString path(RubySyntaxError syntaxError) {
Object path(RubySyntaxError syntaxError) {
if (!syntaxError.hasSourceLocation()) {
return coreStrings().UNKNOWN.createInstance(getContext());
return nil;
}

Source source;
Expand Down

0 comments on commit a4dd7b4

Please sign in to comment.