Files
carbon-lang/toolchain/check/testdata/impl/where_assignment.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

114 lines
4.1 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/primitives.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/where_assignment.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/where_assignment.carbon
// --- fail_todo_basic.carbon
library "[[@TEST_NAME]]";
interface Z {
let Z1: type;
}
impl () as Z {
// CHECK:STDERR: ╭─┤ fail_todo_basic.carbon:[[@LINE+6]]:3
// CHECK:STDERR: -> │ where Z1 = type;
// CHECK:STDERR: · ━━━━━━━━┳━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: semantics TODO: `where assignment decl` [SemanticsTodo]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
where Z1 = type;
}
// --- fail_todo_basic_in_class.carbon
library "[[@TEST_NAME]]";
interface Z {
let Z1: type;
}
class C {
impl as Z {
// CHECK:STDERR: ╭─┤ fail_todo_basic_in_class.carbon:[[@LINE+6]]:5
// CHECK:STDERR: -> │ where Z1 = type;
// CHECK:STDERR: · ━━━━━━━━┳━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: semantics TODO: `where assignment decl` [SemanticsTodo]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
where Z1 = type;
}
}
// --- fail_invalid_scope.carbon
library "[[@TEST_NAME]]";
let Z1: type = type;
// CHECK:STDERR: ╭─┤ fail_invalid_scope.carbon:[[@LINE+8]]:1
// CHECK:STDERR: -> │ where Z1 = type;
// CHECK:STDERR: · ┳━━━━
// CHECK:STDERR: · ┗━━┫ error: `where` assignment declaration found in invalid scope; must be in
// CHECK:STDERR: · ┃ `impl` definition
// CHECK:STDERR: · ┃ [WhereAssignmentInWrongScope]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
where Z1 = type;
// --- fail_fn_invalid_scope.carbon
library "[[@TEST_NAME]]";
let Z1: type = type;
fn F() {
// CHECK:STDERR: ╭─┤ fail_fn_invalid_scope.carbon:[[@LINE+8]]:3
// CHECK:STDERR: -> │ where Z1 = type;
// CHECK:STDERR: · ┳━━━━
// CHECK:STDERR: · ┗━━┫ error: `where` assignment declaration found in invalid scope; must be in
// CHECK:STDERR: · ┃ `impl` definition
// CHECK:STDERR: · ┃ [WhereAssignmentInWrongScope]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
where Z1 = type;
}
// --- fail_region_invalid_scope.carbon
library "[[@TEST_NAME]]";
let Z1: type = type;
fn F() {
// If blocks have a scope that has no declaration scope inst associated with
// them.
if (true) {
// CHECK:STDERR: ╭─┤ fail_region_invalid_scope.carbon:[[@LINE+8]]:5
// CHECK:STDERR: -> │ where Z1 = type;
// CHECK:STDERR: · ┳━━━━
// CHECK:STDERR: · ┗━━┫ error: `where` assignment declaration found in invalid scope; must be
// CHECK:STDERR: · ┃ in `impl` definition
// CHECK:STDERR: · ┃ [WhereAssignmentInWrongScope]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
where Z1 = type;
}
}
// --- fail_class_invalid_scope.carbon
library "[[@TEST_NAME]]";
class C {
let Z1: type = type;
// CHECK:STDERR: ╭─┤ fail_class_invalid_scope.carbon:[[@LINE+8]]:3
// CHECK:STDERR: -> │ where Z1 = type;
// CHECK:STDERR: · ┳━━━━
// CHECK:STDERR: · ┗━━┫ error: `where` assignment declaration found in invalid scope; must be in
// CHECK:STDERR: · ┃ `impl` definition
// CHECK:STDERR: · ┃ [WhereAssignmentInWrongScope]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
where Z1 = type;
}