Files
carbon-lang/toolchain/check/testdata/impl/basic.carbon
T
Geoff RomerandDana Jansens e67b6db910 Give files shorthand names in textual SemIR (#8104)
Shorthand names are intended to be used in the textual format of
references to instructions in another IR (which can't happen now, but
will be possible in a forthcoming PR). The shorthand name uses the file
name (minus the `.carbon` suffix) as a base, and if that base name is
ambiguous within the compilation, it is given a numerical suffix `.N`,
just like other textual IR names. Shorthand names are prefixed with `$`
in the textual format, to distinguish them from inst and scope names.

For example, a file `foo/bar.carbon` has the shorthand name `$bar`, and
an instruction `@baz.%qux` in that file can be referenced from another
file as `$bar.@baz.%qux`.

This PR adds `toolchain/check/testdata/basics/file_name.carbon` to test
this behavior. All other test changes are just applying this change to
the existing textual SemIR dumps.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2026-11-12 23:34:32 +00:00

171 lines
7.3 KiB
Plaintext

// 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
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/basic.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/basic.carbon
// --- basic.carbon
library "[[@TEST_NAME]]";
interface Simple {
fn F();
}
class C {}
//@dump-sem-ir-begin
impl C as Simple {
fn F() {}
}
//@dump-sem-ir-end
// --- fail_invalid_impl.carbon
library "[[@TEST_NAME]]";
interface I {
fn Op(self);
}
class C {}
// This produces an invalid impl.
// CHECK:STDERR: ╭─┤ fail_invalid_impl.carbon:[[@LINE+6]]:6
// CHECK:STDERR: -> │ impl Unknown as I {
// CHECK:STDERR: · ━━━┳━━━
// CHECK:STDERR: · ┗━━┫ error: name `Unknown` not found [NameNotFound]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
impl Unknown as I {
fn Op(unused self) {}
}
// --- fail_import_invalid_impl.carbon
library "[[@TEST_NAME]]";
import library "invalid_impl";
fn F() {
// This impl doesn't exist, but it still tests that we can ignore the
// `impl Unknown as I` on import.
// CHECK:STDERR: ╭─┤ fail_import_invalid_impl.carbon:[[@LINE+8]]:3
// CHECK:STDERR: -> │ C.(I.Op)();
// CHECK:STDERR: · ┳━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot access member of interface `I` in type `type` that does not
// CHECK:STDERR: · ┃ implement that interface
// CHECK:STDERR: · ┃ [MissingImplInMemberAccess]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
C.(I.Op)();
}
// --- fail_conflicting_bad_impls.carbon
library "[[@TEST_NAME]]";
interface I {}
class C(T: type) {}
// CHECK:STDERR: ╭─┤ fail_conflicting_bad_impls.carbon:[[@LINE+6]]:12
// CHECK:STDERR: -> │ final impl invalid as I {}
// CHECK:STDERR: · ━━━┳━━━
// CHECK:STDERR: · ┗━━┫ error: name `invalid` not found [NameNotFound]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
final impl invalid as I {}
// CHECK:STDERR: ╭─┤ fail_conflicting_bad_impls.carbon:[[@LINE+16]]:12
// CHECK:STDERR: -> │ final impl invalid as I {}
// CHECK:STDERR: · ━━━┳━━━
// CHECK:STDERR: · ┗━━┫ error: name `invalid` not found [NameNotFound]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
// CHECK:STDERR: ╭─┤ fail_conflicting_bad_impls.carbon:[[@LINE+10]]:1
// CHECK:STDERR: │ final impl invalid as I {}
// CHECK:STDERR: · ────────────┬────────────
// CHECK:STDERR: · ╰──┤ previous definition was here [ImplPreviousDefinition]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ final impl invalid as I {}
// CHECK:STDERR: · ━━━━━━━━━━━━┳━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: redefinition of `impl <error> as I` [ImplRedefinition]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
final impl invalid as I {}
// CHECK:STDERR: ╭─┤ fail_conflicting_bad_impls.carbon:[[@LINE+6]]:12
// CHECK:STDERR: -> │ final impl alsoinvalid as I {}
// CHECK:STDERR: · ━━━━━┳━━━━━
// CHECK:STDERR: · ┗━━┫ error: name `alsoinvalid` not found [NameNotFound]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
final impl alsoinvalid as I {}
// CHECK:STDERR: ╭─┤ fail_conflicting_bad_impls.carbon:[[@LINE+6]]:14
// CHECK:STDERR: -> │ final impl C(invalid) as I {}
// CHECK:STDERR: · ━━━┳━━━
// CHECK:STDERR: · ┗━━┫ error: name `invalid` not found [NameNotFound]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
final impl C(invalid) as I {}
// CHECK:STDERR: ╭─┤ fail_conflicting_bad_impls.carbon:[[@LINE+16]]:14
// CHECK:STDERR: -> │ final impl C(invalid) as I {}
// CHECK:STDERR: · ━━━┳━━━
// CHECK:STDERR: · ┗━━┫ error: name `invalid` not found [NameNotFound]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
// CHECK:STDERR: ╭─┤ fail_conflicting_bad_impls.carbon:[[@LINE+10]]:1
// CHECK:STDERR: │ final impl C(invalid) as I {}
// CHECK:STDERR: · ──────────────┬─────────────
// CHECK:STDERR: · ╰──┤ previous definition was here [ImplPreviousDefinition]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ final impl C(invalid) as I {}
// CHECK:STDERR: · ━━━━━━━━━━━━━━┳━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: redefinition of `impl <error> as I` [ImplRedefinition]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
final impl C(invalid) as I {}
// CHECK:STDOUT: --- basic.carbon = $basic
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %Simple.type: type = facet_type <@Simple> [concrete]
// CHECK:STDOUT: %C: type = class_type @C [concrete]
// CHECK:STDOUT: %.dd3: <witness> = impl_self_witness %C, @Simple [concrete]
// CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness @C.as.Simple.impl.%Simple.impl_witness_table [concrete]
// CHECK:STDOUT: %C.as.Simple.impl.F.type: type = fn_type @C.as.Simple.impl.F [concrete]
// CHECK:STDOUT: %C.as.Simple.impl.F: %C.as.Simple.impl.F.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: impl_decl @C.as.Simple.impl [concrete] {} {
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
// CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc11: <witness> = impl_self_witness @C.as.Simple.impl.%C.ref, @Simple [concrete = constants.%.dd3]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: impl @C.as.Simple.impl: %C.ref as %Simple.ref {
// CHECK:STDOUT: %C.as.Simple.impl.F.decl: %C.as.Simple.impl.F.type = fn_decl @C.as.Simple.impl.F [concrete = constants.%C.as.Simple.impl.F] {} {}
// CHECK:STDOUT: %Simple.impl_witness_table = impl_witness_table (%C.as.Simple.impl.F.decl), @C.as.Simple.impl [concrete]
// CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness %Simple.impl_witness_table [concrete = constants.%Simple.impl_witness]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .F = %C.as.Simple.impl.F.decl
// CHECK:STDOUT: extend %Simple.ref
// CHECK:STDOUT: witness = %Simple.impl_witness
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @C.as.Simple.impl.F() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: