mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-23 08:42:41 +00:00
This gets us a step closer toward resolving TODOs in member access around facets, by making the lookup into a facet value a "lookup in base" operation instead of a "lookup in type of base". However the base given to find scopes in still remains the facet type of the facet, which is still a TODO. Then we can simplify the "lookup in type of base" case a bit, with a single code path doing the name lookup step. But we keep a TODO where if the type of base is a facet, we change the lookup target to be the facet type of the facet instead. This is toward having name lookup into an interface that is extending a named constraint work correctly with a `Self` in its specific. To perform that name lookup, we will need to tell name lookup what is the base, so that it can replace `Self` with the base. This change gets us in a position where we can correctly provide the base in the `T.F()` (lookup in facet) and `t.F()` (lookup in type of facet) correctly and straightforwardly. We provide a marginally improved diagnostic when looking into a facet with an incomplete facet type, which will move into AppendLookupScopesForConstant once we are looking into the facet directly instead of its type.
135 lines
7.9 KiB
Plaintext
135 lines
7.9 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_fn_invalid_use.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_assoc_fn_invalid_use.carbon
|
|
|
|
// --- fail_member_access.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface I {
|
|
fn F[self: Self]();
|
|
}
|
|
|
|
fn Use(T:! I) {
|
|
// CHECK:STDERR: fail_member_access.carbon:[[@LINE+4]]:3: error: type `<type of F in T>` does not support qualified expressions [QualifiedExprUnsupported]
|
|
// CHECK:STDERR: T.F.member;
|
|
// CHECK:STDERR: ^~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
T.F.member;
|
|
}
|
|
|
|
// CHECK:STDOUT: --- fail_member_access.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
|
|
// CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
|
|
// CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic]
|
|
// CHECK:STDOUT: %pattern_type.fa0: type = pattern_type %Self.binding.as_type [symbolic]
|
|
// CHECK:STDOUT: %I.F.type: type = fn_type @I.F [concrete]
|
|
// CHECK:STDOUT: %I.F: %I.F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
|
|
// CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%I.F.decl [concrete]
|
|
// CHECK:STDOUT: %type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
|
|
// CHECK:STDOUT: %T: %I.type = symbolic_binding T, 0 [symbolic]
|
|
// CHECK:STDOUT: %pattern_type.9d9: type = pattern_type %I.type [concrete]
|
|
// CHECK:STDOUT: %Use.type: type = fn_type @Use [concrete]
|
|
// CHECK:STDOUT: %Use: %Use.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %T.binding.as_type: type = symbolic_binding_type T, 0, %T [symbolic]
|
|
// CHECK:STDOUT: %I.lookup_impl_witness: <witness> = lookup_impl_witness %T, @I [symbolic]
|
|
// CHECK:STDOUT: %.354: type = fn_type_with_self_type %I.F.type, %T [symbolic]
|
|
// CHECK:STDOUT: %impl.elem0: %.354 = impl_witness_access %I.lookup_impl_witness, element0 [symbolic]
|
|
// CHECK:STDOUT: %require_complete: <witness> = require_complete_type %.354 [symbolic]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .I = %I.decl
|
|
// CHECK:STDOUT: .Use = %Use.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
|
|
// CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [concrete = constants.%Use] {
|
|
// CHECK:STDOUT: %T.patt: %pattern_type.9d9 = symbolic_binding_pattern T, 0 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc8: type = splice_block %I.ref [concrete = constants.%I.type] {
|
|
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
|
// CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc8_8.2: %I.type = symbolic_binding T, 0 [symbolic = %T.loc8_8.1 (constants.%T)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @I {
|
|
// CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
|
|
// CHECK:STDOUT: %I.F.decl: %I.F.type = fn_decl @I.F [concrete = constants.%I.F] {
|
|
// CHECK:STDOUT: %self.patt: @I.F.%pattern_type (%pattern_type.fa0) = value_binding_pattern self [concrete]
|
|
// CHECK:STDOUT: %self.param_patt: @I.F.%pattern_type (%pattern_type.fa0) = value_param_pattern %self.patt, call_param0 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %self.param: @I.F.%Self.binding.as_type (%Self.binding.as_type) = value_param call_param0
|
|
// CHECK:STDOUT: %.loc5_14.1: type = splice_block %.loc5_14.2 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)] {
|
|
// CHECK:STDOUT: %Self.ref: %I.type = name_ref Self, @I.%Self [symbolic = %Self (constants.%Self)]
|
|
// CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self.ref [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
|
|
// CHECK:STDOUT: %.loc5_14.2: type = converted %Self.ref, %Self.as_type [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %self: @I.F.%Self.binding.as_type (%Self.binding.as_type) = value_binding self, %self.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %I.F.decl [concrete = constants.%assoc0]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: .F = %assoc0
|
|
// CHECK:STDOUT: witness = (%I.F.decl)
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @I.F(@I.%Self: %I.type) {
|
|
// CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self)]
|
|
// CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
|
|
// CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic = %pattern_type (constants.%pattern_type.fa0)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn(%self.param: @I.F.%Self.binding.as_type (%Self.binding.as_type));
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @Use(%T.loc8_8.2: %I.type) {
|
|
// CHECK:STDOUT: %T.loc8_8.1: %I.type = symbolic_binding T, 0 [symbolic = %T.loc8_8.1 (constants.%T)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %T.binding.as_type: type = symbolic_binding_type T, 0, %T.loc8_8.1 [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
|
|
// CHECK:STDOUT: %I.lookup_impl_witness: <witness> = lookup_impl_witness %T.loc8_8.1, @I [symbolic = %I.lookup_impl_witness (constants.%I.lookup_impl_witness)]
|
|
// CHECK:STDOUT: %.loc13_4.2: type = fn_type_with_self_type constants.%I.F.type, %T.loc8_8.1 [symbolic = %.loc13_4.2 (constants.%.354)]
|
|
// CHECK:STDOUT: %impl.elem0.loc13_4.2: @Use.%.loc13_4.2 (%.354) = impl_witness_access %I.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc13_4.2 (constants.%impl.elem0)]
|
|
// CHECK:STDOUT: %require_complete: <witness> = require_complete_type %.loc13_4.2 [symbolic = %require_complete (constants.%require_complete)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %T.ref: %I.type = name_ref T, %T.loc8_8.2 [symbolic = %T.loc8_8.1 (constants.%T)]
|
|
// CHECK:STDOUT: %T.as_type: type = facet_access_type %T.ref [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
|
|
// CHECK:STDOUT: %.loc13_4.1: type = converted %T.ref, %T.as_type [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
|
|
// CHECK:STDOUT: %F.ref: %I.assoc_type = name_ref F, @I.%assoc0 [concrete = constants.%assoc0]
|
|
// CHECK:STDOUT: %impl.elem0.loc13_4.1: @Use.%.loc13_4.2 (%.354) = impl_witness_access constants.%I.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc13_4.2 (constants.%impl.elem0)]
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @I.F(constants.%Self) {
|
|
// CHECK:STDOUT: %Self => constants.%Self
|
|
// CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
|
|
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.fa0
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Use(constants.%T) {
|
|
// CHECK:STDOUT: %T.loc8_8.1 => constants.%T
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|