Skip to content

Commit

Permalink
Handle impl with bad interface on import (carbon-language#5051)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
  • Loading branch information
josh11b and josh11b authored Mar 6, 2025
1 parent ea1a0c8 commit 331f55f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
15 changes: 11 additions & 4 deletions toolchain/check/import_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2134,10 +2134,14 @@ struct SpecificInterfaceData {
static auto GetLocalSpecificInstanceData(
ImportRefResolver& resolver, SemIR::SpecificInterface import_interface)
-> SpecificInterfaceData {
return {.interface_const_id = GetLocalConstantId(
resolver, resolver.import_interfaces()
.Get(import_interface.interface_id)
.first_owning_decl_id),
SemIR::ConstantId interface_const_id = SemIR::ConstantId::None;
if (import_interface.interface_id.has_value()) {
interface_const_id =
GetLocalConstantId(resolver, resolver.import_interfaces()
.Get(import_interface.interface_id)
.first_owning_decl_id);
}
return {.interface_const_id = interface_const_id,
.specific_data =
GetLocalSpecificData(resolver, import_interface.specific_id)};
}
Expand All @@ -2146,6 +2150,9 @@ static auto GetLocalSpecificInterface(ImportContext& context,
SemIR::SpecificId import_specific_id,
SpecificInterfaceData interface_data)
-> SemIR::SpecificInterface {
if (!interface_data.interface_const_id.has_value()) {
return SemIR::SpecificInterface::None;
}
// Find the corresponding interface type. For a non-generic interface,
// this is the type of the interface declaration. For a generic interface,
// build a interface type referencing this specialization of the generic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// EXTRA-ARGS: --no-dump-sem-ir
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/no_prelude/import_impl_with_no_interface.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/no_prelude/import_impl_with_no_interface.carbon

// --- fail_lib.carbon
library "[[@TEST_NAME]]";

// CHECK:STDERR: fail_lib.carbon:[[@LINE+4]]:18: error: name `Undeclared` not found [NameNotFound]
// CHECK:STDERR: impl {.i: ()} as Undeclared {
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR:
impl {.i: ()} as Undeclared {
fn F() {}
}

interface Instance {
fn G[self: Self]();
}

impl {.i: ()} as Instance {
fn G[self: Self]() {}
}

// --- import_instance_success.carbon
library "[[@TEST_NAME]]";

import library "lib";

fn InstanceCallImport(n: {.i: ()}) {
n.(Instance.G)();
}

0 comments on commit 331f55f

Please sign in to comment.