Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle impl with bad interface on import #5051

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions toolchain/check/import_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,10 +2131,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 @@ -2143,6 +2147,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)();
}