Fix a crash when Core is poisoned (#5838)

There are probably other ways to reproduce this, but this is roughly how
I ran into it.
This commit is contained in:
Jon Ross-Perkins
2025-07-22 22:31:41 +00:00
committed by GitHub
parent c90c6728fd
commit fdd68dcbe6
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -648,7 +648,7 @@ auto ImportNameFromOtherPackage(
const auto* import_scope_entry = LookupNameInImport(
*import_ir.sem_ir, import_scope_id, name_id, identifier);
if (!import_scope_entry) {
if (!import_scope_entry || !import_scope_entry->result.is_found()) {
continue;
}
SemIR::InstId import_scope_inst_id =
@@ -12,6 +12,8 @@
// --- fail_implicitly_poison_core.carbon
library "[[@TEST_NAME]]";
// CHECK:STDERR: fail_implicitly_poison_core.carbon:[[@LINE+4]]:9: error: `Core.Bool` implicitly referenced here, but package `Core` not found [CoreNotFound]
// CHECK:STDERR: fn F(x: bool);
// CHECK:STDERR: ^~~~
@@ -19,3 +21,27 @@
fn F(x: bool);
class r#Core {}
// --- fail_poisoned_core.carbon
package Core library "[[@TEST_NAME]]";
// This introduces a poisoned name in `Core`.
// CHECK:STDERR: fail_poisoned_core.carbon:[[@LINE+4]]:8: error: name `Core.Int` implicitly referenced here, but not found [CoreNameNotFound]
// CHECK:STDERR: var x: i32;
// CHECK:STDERR: ^~~
// CHECK:STDERR:
var x: i32;
// --- fail_use_poisoned_core.carbon
library "[[@TEST_NAME]]";
import Core library "poisoned_core";
// This accesses the poisoned name in `Core`.
// CHECK:STDERR: fail_use_poisoned_core.carbon:[[@LINE+4]]:9: error: name `Core.Int` implicitly referenced here, but not found [CoreNameNotFound]
// CHECK:STDERR: fn F(b: i32);
// CHECK:STDERR: ^~~
// CHECK:STDERR:
fn F(b: i32);