Skip to content

Commit

Permalink
Fix crash in go_to_type_definition.cc (sorbet#6135)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jez authored Aug 1, 2022
1 parent 308815a commit 21059f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions main/lsp/DefLocSaver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ void DefLocSaver::postTransformMethodDef(core::Context ctx, ast::ExpressionPtr &
// localExp should never be null, but guard against the possibility.
if (localExp && lspQuery.matchesLoc(ctx.locAt(localExp->loc))) {
tp.type = argType.type;
if (tp.type == nullptr) {
tp.type = core::Types::untyped(ctx, methodDef.symbol);
}
tp.origins.emplace_back(ctx.locAt(localExp->loc));
core::lsp::QueryResponse::pushQueryResponse(
ctx,
Expand Down
5 changes: 5 additions & 0 deletions test/testdata/lsp/go_to_type_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ class TestClass
a_or_b_or_mn = T.let(A.new, T.any(A, B, T.all(M, N)))
puts a_or_b_or_mn
# ^ type: ABMN

def example(x)
# ^ type: (nothing)
end
end

0 comments on commit 21059f0

Please sign in to comment.