Files
carbon-lang/toolchain/check/testdata/impl/fail_impl_bad_assoc_const.carbon
T
Dana Jansens 6814311c72 Move impl requirement checking to the end of the impl definition (#8138)
Previously the design required the impl declaration to meet its
requirements, but in proposal #5168 that was changed. The rules are
provided in a [table here] and from the [changes here].

Now associated constants can be set inside the body of the impl
definition, which means requirements set in the impl declaration (like
`.A impls Y` or `.B == C`) can't be checked until the end of the
definition where we know all associated constants have been set.

Likewise, the check that all associated constants have been set needs to
be done at the end of the impl definition instead of at the start. And
requirements from require decls in the interface being impl'd must also
be met at the end of the definition now.

[table here]:
https://github.com/carbon-language/carbon-lang/blob/b7ea32c3a49620fae12f0b2298c81d429a20eab3/proposals/p005168-forward-impl-declaration-of-an-incomplete-interface.md#proposed-rules
[changes here]:
https://github.com/carbon-language/carbon-lang/blob/b7ea32c3a49620fae12f0b2298c81d429a20eab3/proposals/p005168-forward-impl-declaration-of-an-incomplete-interface.md#associated-constants-may-be-assigned-in-the-body-of-an-impl-definition
2026-11-18 14:07:47 +00:00

93 lines
4.7 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
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/fail_impl_bad_assoc_const.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_impl_bad_assoc_const.carbon
interface I { let T: type; }
// CHECK:STDERR: ╭─┤ fail_impl_bad_assoc_const.carbon:[[@LINE+12]]:1
// CHECK:STDERR: │ interface I { let T: type; }
// CHECK:STDERR: · ───┬───
// CHECK:STDERR: · ╰──┤ associated constant declared here
// CHECK:STDERR: · │ [AssociatedConstantHere]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ impl () as I {}
// CHECK:STDERR: · ━━━━━━┳━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: associated constant T not given a value in impl of interface I
// CHECK:STDERR: · ┃ [ImplAssociatedConstantNeedsValue]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
impl () as I {}
// CHECK:STDOUT: --- fail_impl_bad_assoc_const.carbon = $fail_impl_bad_assoc_const
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
// CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
// CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
// CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.WithSelf.%T [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
// CHECK:STDOUT: %.2ef: <witness> = impl_self_witness %empty_tuple.type, @I [concrete]
// CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness @empty_tuple.type.as.I.impl.%I.impl_witness_table [concrete]
// CHECK:STDOUT: %I.facet: %I.type = facet_value %empty_tuple.type, (%I.impl_witness) [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
// CHECK:STDOUT: .I = %I.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
// CHECK:STDOUT: impl_decl @empty_tuple.type.as.I.impl [concrete] {} {
// CHECK:STDOUT: %.loc29_7.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc29_7.2: type = converted %.loc29_7.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
// CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc29: <witness> = impl_self_witness @empty_tuple.type.as.I.impl.%.loc29_7.2, @I [concrete = constants.%.2ef]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: interface @I {
// CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
// CHECK:STDOUT: %I.WithSelf.decl = interface_with_self_decl @I [concrete]
// CHECK:STDOUT:
// CHECK:STDOUT: !with Self:
// CHECK:STDOUT: %T: type = assoc_const_decl @T [concrete] {
// CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.WithSelf.%T [concrete = constants.%assoc0]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = %Self
// CHECK:STDOUT: .T = @T.%assoc0
// CHECK:STDOUT: witness = (@I.WithSelf.%T)
// CHECK:STDOUT:
// CHECK:STDOUT: !requires:
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: impl @empty_tuple.type.as.I.impl: %.loc29_7.2 as %I.ref {
// CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (<error>), @empty_tuple.type.as.I.impl [concrete]
// CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness %I.impl_witness_table [concrete = constants.%I.impl_witness]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: extend %I.ref
// CHECK:STDOUT: witness = %I.impl_witness
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @I.WithSelf(constants.%Self) {
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @I.WithSelf(constants.%I.facet) {
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: }
// CHECK:STDOUT: