Skip to content

Commit 21059f0

Browse files
authored
Fix crash in go_to_type_definition.cc (sorbet#6135)
* Add a failing test + exec test/lsp_test_runner --single_test=test/testdata/lsp/go_to_type_definition.rb Pausing Resuming [doctest] doctest version is "2.4.1" [doctest] run with "--help" for options [2022-08-01 22:09:09.445] [fatalFallback] [error] Exception::raise(): ./core/TypePtr.h:223 enforced condition store != 0 has failed: (no message provided) [2022-08-01 22:09:09.490] [fatalFallback] [error] Backtrace: #3 0xc859b2 #4 0xdbc197 sorbet::core::TypePtr::tag() #5 0xef9fe7 sorbet::realmain::lsp::(anonymous namespace)::locsForType()::$_13::operator()() #6 0xef95d3 sorbet::typecaseHelper<>() #7 0xef8f85 sorbet::typecase<>() #8 0xef8b0a sorbet::realmain::lsp::(anonymous namespace)::locsForType() #9 0xef859f sorbet::realmain::lsp::TypeDefinitionTask::runRequest() #10 0xda699c sorbet::realmain::lsp::LSPRequestTask::run() #11 0xf160f4 sorbet::realmain::lsp::(anonymous namespace)::TypecheckerTask::run() #12 0xf1454e sorbet::realmain::lsp::LSPTypecheckerCoordinator::asyncRunInternal() #13 0xf14620 sorbet::realmain::lsp::LSPTypecheckerCoordinator::syncRun() #14 0xf12d44 sorbet::realmain::lsp::LSPLoop::runTask() #15 0xf12698 sorbet::realmain::lsp::LSPLoop::processRequests() #16 0xf0410d sorbet::realmain::lsp::SingleThreadedLSPWrapper::getLSPResponsesFor() #17 0xcbf398 sorbet::test::getLSPResponsesFor() #18 0xcbcece sorbet::test::getLSPResponsesFor() #19 0xcf1709 sorbet::test::TypeDefAssertion::check() #20 0xbbff18 sorbet::test::_DOCTEST_ANON_FUNC_71() #21 0x1d060a9 doctest::Context::run() #22 0xbc2380 main #23 0x7f162d27c083 __libc_start_main #24 0xbb34ae _start [2022-08-01 22:09:09.496] [fatalFallback] [error] Backtrace: #3 0x1d8f6e8 std::terminate() #4 0xbcb94b #5 0xdbc1c9 #6 0xef9fe7 sorbet::realmain::lsp::(anonymous namespace)::locsForType()::$_13::operator()() #7 0xef95d3 sorbet::typecaseHelper<>() #8 0xef8f85 sorbet::typecase<>() #9 0xef8b0a sorbet::realmain::lsp::(anonymous namespace)::locsForType() #10 0xef859f sorbet::realmain::lsp::TypeDefinitionTask::runRequest() #11 0xda699c sorbet::realmain::lsp::LSPRequestTask::run() #12 0xf160f4 sorbet::realmain::lsp::(anonymous namespace)::TypecheckerTask::run() #13 0xf1454e sorbet::realmain::lsp::LSPTypecheckerCoordinator::asyncRunInternal() #14 0xf14620 sorbet::realmain::lsp::LSPTypecheckerCoordinator::syncRun() #15 0xf12d44 sorbet::realmain::lsp::LSPLoop::runTask() #16 0xf12698 sorbet::realmain::lsp::LSPLoop::processRequests() #17 0xf0410d sorbet::realmain::lsp::SingleThreadedLSPWrapper::getLSPResponsesFor() #18 0xcbf398 sorbet::test::getLSPResponsesFor() #19 0xcbcece sorbet::test::getLSPResponsesFor() #20 0xcf1709 sorbet::test::TypeDefAssertion::check() #21 0xbbff18 sorbet::test::_DOCTEST_ANON_FUNC_71() #22 0x1d060a9 doctest::Context::run() #23 0xbc2380 main #24 0x7f162d27c083 __libc_start_main #25 0xbb34ae _start libc++abi: terminate_handler unexpectedly returned =============================================================================== test/lsp_test_runner.cc:497: TEST CASE: LSPTest test/lsp_test_runner.cc:497: FATAL ERROR: test case CRASHED: SIGABRT - Abort (abnormal termination) signal * Set type to untyped if null
1 parent 308815a commit 21059f0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

main/lsp/DefLocSaver.cc

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ void DefLocSaver::postTransformMethodDef(core::Context ctx, ast::ExpressionPtr &
3030
// localExp should never be null, but guard against the possibility.
3131
if (localExp && lspQuery.matchesLoc(ctx.locAt(localExp->loc))) {
3232
tp.type = argType.type;
33+
if (tp.type == nullptr) {
34+
tp.type = core::Types::untyped(ctx, methodDef.symbol);
35+
}
3336
tp.origins.emplace_back(ctx.locAt(localExp->loc));
3437
core::lsp::QueryResponse::pushQueryResponse(
3538
ctx,

test/testdata/lsp/go_to_type_definition.rb

+5
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ class TestClass
4848
a_or_b_or_mn = T.let(A.new, T.any(A, B, T.all(M, N)))
4949
puts a_or_b_or_mn
5050
# ^ type: ABMN
51+
52+
def example(x)
53+
# ^ type: (nothing)
54+
end
5155
end
56+

0 commit comments

Comments
 (0)