Skip to content

Commit af68d97

Browse files
committed
Fix Polyglot.import to raise NameError if not found
* Instead of returning nil unintentionally from Truffle::Interop.lookup_symbol.
1 parent 6c9c28b commit af68d97

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

spec/truffle/interop/import_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
Truffle::Interop.import(:imports_an_object).should == object
1818
end
1919

20-
it "returns nil because Truffle::Interop.lookup_symbol returns nil if not found" do
21-
Truffle::Interop.import(:not_registered_export_test).should == nil
20+
it "raises NameError if not found" do
21+
-> {
22+
Truffle::Interop.import(:not_registered_export_test)
23+
}.should raise_error(NameError, "import 'not_registered_export_test' not found")
2224
end
2325

2426
end

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ protected Object findExportedSymbol(RubyContext context, String symbolName, bool
145145
return null;
146146
}
147147

148-
return context.send(context.getCoreLibrary().getTruffleInteropModule(), "lookup_symbol", context.getSymbolTable().getSymbol(symbolName));
148+
Object implicit = context.send(context.getCoreLibrary().getTruffleInteropModule(), "lookup_symbol", context.getSymbolTable().getSymbol(symbolName));
149+
if (implicit == NotProvided.INSTANCE) {
150+
return null;
151+
} else {
152+
return implicit;
153+
}
149154
}
150155

151156
@SuppressWarnings("deprecation")

src/main/ruby/core/truffle/interop.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def self.lookup_symbol(name)
113113
elsif Truffle::SymbolOperations.is_constant?(name) && Object.const_defined?(name)
114114
Object.const_get(name)
115115
else
116-
nil
116+
undefined
117117
end
118118
end
119119

0 commit comments

Comments
 (0)