Skip to content

Commit f4f3f84

Browse files
authored
Fix crash in pinning autocorrect (sorbet#3924)
* Add ENFORCE that would have made error more obvious * Add failing test Fails with this backtrace: Exception::raise(): core/Loc.cc:270 enforced condition exists() has failed: Can't take source of Loc that doesn't exist Backtrace: #3 0x1725725 sorbet::core::Loc::source() #4 0x120e0e1 sorbet::infer::Environment::processBinding() #5 0x11fae5b sorbet::infer::Inference::run() #6 0xed1a88 sorbet::realmain::pipeline::CFGCollectorAndTyper::preTransformMethodDef() #7 0xed185b sorbet::ast::CALL_MEMBER_impl_preTransformMethodDef<>::call<>() #8 0xecf90c sorbet::ast::TreeMapper<>::mapMethodDef() #9 0xece3ff sorbet::ast::TreeMapper<>::mapIt() #10 0xecf81f sorbet::ast::TreeMapper<>::mapClassDef() #11 0xece37a sorbet::ast::TreeMapper<>::mapIt() #12 0xed1409 sorbet::ast::TreeMapper<>::mapInsSeq() #13 0xecef9f sorbet::ast::TreeMapper<>::mapIt() #14 0xebc5d9 sorbet::ast::TreeMap::apply<>() #15 0xea2971 sorbet::realmain::pipeline::typecheckOne() #16 0xeb3dc6 sorbet::realmain::pipeline::typecheck()::$_4::operator()() #17 0xeb3acd std::__1::__invoke<>() #18 0xeb3a7d std::__1::__invoke_void_return_wrapper<>::__call<>() #19 0xeb3a4d std::__1::__function::__alloc_func<>::operator()() #20 0xeb2bee std::__1::__function::__func<>::operator()() #21 0x177e015 std::__1::__function::__value_func<>::operator()() #22 0x177ddb5 std::__1::function<>::operator()() #23 0x17fc90e sorbet::WorkerPoolImpl::multiplexJob() #24 0xea5633 sorbet::realmain::pipeline::typecheck() #25 0xafb232 sorbet::realmain::realmain() #26 0xaf70f2 main #27 0x7fba7de990b3 __libc_start_main #28 0xaf702e _start * Fix failing test
1 parent 3be845c commit f4f3f84

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

core/Loc.cc

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ string Loc::filePosToString(const GlobalState &gs, bool showFull) const {
273273
}
274274

275275
string Loc::source(const GlobalState &gs) const {
276+
ENFORCE(exists(), "Can't take source of Loc that doesn't exist");
276277
auto source = this->file().data(gs).source();
277278
return string(source.substr(beginPos(), endPos() - beginPos()));
278279
}

infer/environment.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ core::TypePtr Environment::processBinding(core::Context ctx, const cfg::CFG &inW
13881388
e.addErrorSection(core::ErrorSection(core::ErrorColors::format(
13891389
"Attempting to change type to: `{}`\n", tp.type.show(ctx))));
13901390

1391-
if (cur.origins.size() == 1) {
1391+
if (cur.origins.size() == 1 && cur.origins[0].exists()) {
13921392
// NOTE(nelhage): We assume that if there is
13931393
// a single definition location, that
13941394
// corresponds to an initial
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# typed: true
2+
3+
x = self
4+
5+
1.times do
6+
x = 10 # error: Changing the type of a variable in a loop is not permitted
7+
end

0 commit comments

Comments
 (0)