mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 04:28:14 +00:00
This switches from the `CollectNamesInBlock` approach for entities, to instead traversing entities as they're encountered. For example, when traversing constants, when a type is found, the entity will have its block queued for processing. This leads to a change in the traversal order, which affects disambiguation done by numeric sequencing (since that's just showing the traversal order). This will allow for simpler "name based on name" logic. This is something I plan to use for: - impls: `<type>.as.<interface>.impl` - functions: `<entity>.<member function>` - Note an impl may be used as the entity for a bound function. By naming the entities as they're encountered, I'll be able to rely on the generated names rather than recalculating them. To assist this, I'm also differentiating between the ambiguous and disambiguated name. Otherwise, we could end up with things like `<function>.<disambiguator>.<call>.<other disambiguator>`, where the repeated disambiguator may not be necessary in order to get full disambiguation. It's also a smaller delta from the current output. Note, changing `Name` to a class felt appropriate given its shape. I was also noticing that parts of its API were unused, and the class helps detect unused private members. --------- Co-authored-by: Geoff Romer <gromer@google.com>
147 lines
5.4 KiB
Plaintext
147 lines
5.4 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/interface/fail_assoc_const_not_binding.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_assoc_const_not_binding.carbon
|
|
|
|
// --- fail_tuple_pattern.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface I {
|
|
// CHECK:STDERR: fail_tuple_pattern.carbon:[[@LINE+4]]:7: error: found tuple pattern in associated constant declaration; expected symbolic binding pattern [ExpectedSingleBindingInAssociatedConstant]
|
|
// CHECK:STDERR: let (T:! type, U:! type);
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
let (T:! type, U:! type);
|
|
}
|
|
|
|
// --- fail_tuple_pattern_with_default.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface I {
|
|
// CHECK:STDERR: fail_tuple_pattern_with_default.carbon:[[@LINE+4]]:15: error: found tuple pattern in associated constant declaration; expected symbolic binding pattern [ExpectedSingleBindingInAssociatedConstant]
|
|
// CHECK:STDERR: default let (T:! type, U:! type) = ({}, {});
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
default let (T:! type, U:! type) = ({}, {});
|
|
}
|
|
|
|
// --- fail_var_pattern.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface I {
|
|
// CHECK:STDERR: fail_var_pattern.carbon:[[@LINE+8]]:11: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
|
// CHECK:STDERR: let var T:! type;
|
|
// CHECK:STDERR: ^~~~~~~~
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_var_pattern.carbon:[[@LINE+4]]:19: error: `var` pattern cannot declare a compile-time binding [CompileTimeBindingInVarDecl]
|
|
// CHECK:STDERR: let var T:! type;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
let var T:! type;
|
|
}
|
|
|
|
// --- fail_var_pattern_with_default.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface I {
|
|
// CHECK:STDERR: fail_var_pattern_with_default.carbon:[[@LINE+8]]:19: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
|
// CHECK:STDERR: default let var T:! type = {};
|
|
// CHECK:STDERR: ^~~~~~~~
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_var_pattern_with_default.carbon:[[@LINE+4]]:28: error: `var` pattern cannot declare a compile-time binding [CompileTimeBindingInVarDecl]
|
|
// CHECK:STDERR: default let var T:! type = {};
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
default let var T:! type = {};
|
|
}
|
|
|
|
// CHECK:STDOUT: --- fail_tuple_pattern.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
|
|
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
|
|
// 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: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @I {
|
|
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: has_error
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: assoc_const @<null name> T:! type;
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: assoc_const @<null name> U:! type;
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_tuple_pattern_with_default.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
|
|
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
|
|
// 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: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @I {
|
|
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: has_error
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: assoc_const @<null name> T:! type;
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: assoc_const @<null name> U:! type;
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_var_pattern.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @I {
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = <unexpected>.inst17
|
|
// CHECK:STDOUT: witness = invalid
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_var_pattern_with_default.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @I {
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = <unexpected>.inst17
|
|
// CHECK:STDOUT: witness = invalid
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|