| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- // 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/int.carbon
- //
- // AUTOUPDATE
- // TIP: To test this file alone, run:
- // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/generic/member_lookup.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/member_lookup.carbon
- // --- member_access.carbon
- library "[[@TEST_NAME]]";
- base class Base(T:! type) {
- var b: T;
- }
- class Derived(T:! type) {
- extend base: Base(T);
- var d: T;
- }
- fn AccessDerived[T:! Core.Copy](x: Derived(T)) -> T {
- //@dump-sem-ir-begin
- return x.d;
- //@dump-sem-ir-end
- }
- fn AccessBase[T:! Core.Copy](x: Derived(T)) -> T {
- //@dump-sem-ir-begin
- return x.b;
- //@dump-sem-ir-end
- }
- fn AccessConcrete(x: Derived(i32)) -> i32 {
- return x.b;
- }
- // --- fail_no_member.carbon
- library "[[@TEST_NAME]]";
- base class Base(T:! type) {
- var b: T;
- }
- class Derived(T:! type) {
- extend base: Base(T);
- var d: T;
- }
- fn AccessMissingBase[T:! type](x: Base(T)) -> T {
- // CHECK:STDERR: fail_no_member.carbon:[[@LINE+4]]:10: error: member name `nonesuch` not found in `Base(T)` [MemberNameNotFoundInSpecificScope]
- // CHECK:STDERR: return x.nonesuch;
- // CHECK:STDERR: ^~~~~~~~~~
- // CHECK:STDERR:
- return x.nonesuch;
- }
- fn AccessMissingDerived[T:! type](x: Derived(T)) -> T {
- // CHECK:STDERR: fail_no_member.carbon:[[@LINE+4]]:10: error: member name `nonesuch` not found in `Derived(T)` [MemberNameNotFoundInSpecificScope]
- // CHECK:STDERR: return x.nonesuch;
- // CHECK:STDERR: ^~~~~~~~~~
- // CHECK:STDERR:
- return x.nonesuch;
- }
- fn AccessMissingConcrete(x: Derived(i32)) -> i32 {
- // CHECK:STDERR: fail_no_member.carbon:[[@LINE+4]]:10: error: member name `nonesuch` not found in `Derived(i32)` [MemberNameNotFoundInSpecificScope]
- // CHECK:STDERR: return x.nonesuch;
- // CHECK:STDERR: ^~~~~~~~~~
- // CHECK:STDERR:
- return x.nonesuch;
- }
- // CHECK:STDOUT: --- member_access.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
- // CHECK:STDOUT: %T.be8: %Copy.type = bind_symbolic_name T, 0 [symbolic]
- // CHECK:STDOUT: %T.binding.as_type: type = symbolic_binding_type T, 0, %T.be8 [symbolic]
- // CHECK:STDOUT: %Derived.b36: type = class_type @Derived, @Derived(%T.binding.as_type) [symbolic]
- // CHECK:STDOUT: %pattern_type.50f: type = pattern_type %Derived.b36 [symbolic]
- // CHECK:STDOUT: %pattern_type.17e4b7.1: type = pattern_type %T.binding.as_type [symbolic]
- // CHECK:STDOUT: %require_complete.1cd: <witness> = require_complete_type %T.binding.as_type [symbolic]
- // CHECK:STDOUT: %Base.342: type = class_type @Base, @Base(%T.binding.as_type) [symbolic]
- // CHECK:STDOUT: %require_complete.254: <witness> = require_complete_type %Base.342 [symbolic]
- // CHECK:STDOUT: %Derived.elem.0da: type = unbound_element_type %Derived.b36, %T.binding.as_type [symbolic]
- // CHECK:STDOUT: %Base.elem.b9e: type = unbound_element_type %Base.342, %T.binding.as_type [symbolic]
- // CHECK:STDOUT: %Copy.Op.type: type = fn_type @Copy.Op [concrete]
- // CHECK:STDOUT: %Copy.lookup_impl_witness.e15: <witness> = lookup_impl_witness %T.be8, @Copy [symbolic]
- // CHECK:STDOUT: %.427: type = fn_type_with_self_type %Copy.Op.type, %T.be8 [symbolic]
- // CHECK:STDOUT: %impl.elem0.168: %.427 = impl_witness_access %Copy.lookup_impl_witness.e15, element0 [symbolic]
- // CHECK:STDOUT: %specific_impl_fn.2ce: <specific function> = specific_impl_function %impl.elem0.168, @Copy.Op(%T.be8) [symbolic]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: generic fn @AccessDerived(%T.loc13_18.2: %Copy.type) {
- // CHECK:STDOUT: <elided>
- // CHECK:STDOUT:
- // CHECK:STDOUT: !definition:
- // CHECK:STDOUT: <elided>
- // CHECK:STDOUT: %Derived.elem: type = unbound_element_type %Derived.loc13_45.1, %T.binding.as_type [symbolic = %Derived.elem (constants.%Derived.elem.0da)]
- // CHECK:STDOUT: %Copy.lookup_impl_witness: <witness> = lookup_impl_witness %T.loc13_18.1, @Copy [symbolic = %Copy.lookup_impl_witness (constants.%Copy.lookup_impl_witness.e15)]
- // CHECK:STDOUT: %.loc15_11.4: type = fn_type_with_self_type constants.%Copy.Op.type, %T.loc13_18.1 [symbolic = %.loc15_11.4 (constants.%.427)]
- // CHECK:STDOUT: %impl.elem0.loc15_11.2: @AccessDerived.%.loc15_11.4 (%.427) = impl_witness_access %Copy.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc15_11.2 (constants.%impl.elem0.168)]
- // CHECK:STDOUT: %specific_impl_fn.loc15_11.2: <specific function> = specific_impl_function %impl.elem0.loc15_11.2, @Copy.Op(%T.loc13_18.1) [symbolic = %specific_impl_fn.loc15_11.2 (constants.%specific_impl_fn.2ce)]
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn(%x.param: @AccessDerived.%Derived.loc13_45.1 (%Derived.b36)) -> %return.param: @AccessDerived.%T.binding.as_type (%T.binding.as_type) {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %x.ref: @AccessDerived.%Derived.loc13_45.1 (%Derived.b36) = name_ref x, %x
- // CHECK:STDOUT: %d.ref: @AccessDerived.%Derived.elem (%Derived.elem.0da) = name_ref d, @Derived.%.loc10 [concrete = @Derived.%.loc10]
- // CHECK:STDOUT: %.loc15_11.1: ref @AccessDerived.%T.binding.as_type (%T.binding.as_type) = class_element_access %x.ref, element1
- // CHECK:STDOUT: %.loc15_11.2: @AccessDerived.%T.binding.as_type (%T.binding.as_type) = bind_value %.loc15_11.1
- // CHECK:STDOUT: %impl.elem0.loc15_11.1: @AccessDerived.%.loc15_11.4 (%.427) = impl_witness_access constants.%Copy.lookup_impl_witness.e15, element0 [symbolic = %impl.elem0.loc15_11.2 (constants.%impl.elem0.168)]
- // CHECK:STDOUT: %bound_method.loc15_11.1: <bound method> = bound_method %.loc15_11.2, %impl.elem0.loc15_11.1
- // CHECK:STDOUT: %specific_impl_fn.loc15_11.1: <specific function> = specific_impl_function %impl.elem0.loc15_11.1, @Copy.Op(constants.%T.be8) [symbolic = %specific_impl_fn.loc15_11.2 (constants.%specific_impl_fn.2ce)]
- // CHECK:STDOUT: %bound_method.loc15_11.2: <bound method> = bound_method %.loc15_11.2, %specific_impl_fn.loc15_11.1
- // CHECK:STDOUT: <elided>
- // CHECK:STDOUT: %.loc15_11.3: init @AccessDerived.%T.binding.as_type (%T.binding.as_type) = call %bound_method.loc15_11.2(%.loc15_11.2) to %.loc13_48
- // CHECK:STDOUT: return %.loc15_11.3 to %return
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: generic fn @AccessBase(%T.loc19_15.2: %Copy.type) {
- // CHECK:STDOUT: <elided>
- // CHECK:STDOUT:
- // CHECK:STDOUT: !definition:
- // CHECK:STDOUT: <elided>
- // CHECK:STDOUT: %Base: type = class_type @Base, @Base(%T.binding.as_type) [symbolic = %Base (constants.%Base.342)]
- // CHECK:STDOUT: %require_complete.loc21_11: <witness> = require_complete_type %Base [symbolic = %require_complete.loc21_11 (constants.%require_complete.254)]
- // CHECK:STDOUT: %Base.elem: type = unbound_element_type %Base, %T.binding.as_type [symbolic = %Base.elem (constants.%Base.elem.b9e)]
- // CHECK:STDOUT: %require_complete.loc21_13: <witness> = require_complete_type %T.binding.as_type [symbolic = %require_complete.loc21_13 (constants.%require_complete.1cd)]
- // CHECK:STDOUT: %Copy.lookup_impl_witness: <witness> = lookup_impl_witness %T.loc19_15.1, @Copy [symbolic = %Copy.lookup_impl_witness (constants.%Copy.lookup_impl_witness.e15)]
- // CHECK:STDOUT: %.loc21_11.6: type = fn_type_with_self_type constants.%Copy.Op.type, %T.loc19_15.1 [symbolic = %.loc21_11.6 (constants.%.427)]
- // CHECK:STDOUT: %impl.elem0.loc21_11.2: @AccessBase.%.loc21_11.6 (%.427) = impl_witness_access %Copy.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc21_11.2 (constants.%impl.elem0.168)]
- // CHECK:STDOUT: %specific_impl_fn.loc21_11.2: <specific function> = specific_impl_function %impl.elem0.loc21_11.2, @Copy.Op(%T.loc19_15.1) [symbolic = %specific_impl_fn.loc21_11.2 (constants.%specific_impl_fn.2ce)]
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn(%x.param: @AccessBase.%Derived.loc19_42.1 (%Derived.b36)) -> %return.param: @AccessBase.%T.binding.as_type (%T.binding.as_type) {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %x.ref: @AccessBase.%Derived.loc19_42.1 (%Derived.b36) = name_ref x, %x
- // CHECK:STDOUT: %b.ref: @AccessBase.%Base.elem (%Base.elem.b9e) = name_ref b, @Base.%.loc5 [concrete = @Base.%.loc5]
- // CHECK:STDOUT: %.loc21_11.1: ref @AccessBase.%Base (%Base.342) = class_element_access %x.ref, element0
- // CHECK:STDOUT: %.loc21_11.2: ref @AccessBase.%Base (%Base.342) = converted %x.ref, %.loc21_11.1
- // CHECK:STDOUT: %.loc21_11.3: ref @AccessBase.%T.binding.as_type (%T.binding.as_type) = class_element_access %.loc21_11.2, element0
- // CHECK:STDOUT: %.loc21_11.4: @AccessBase.%T.binding.as_type (%T.binding.as_type) = bind_value %.loc21_11.3
- // CHECK:STDOUT: %impl.elem0.loc21_11.1: @AccessBase.%.loc21_11.6 (%.427) = impl_witness_access constants.%Copy.lookup_impl_witness.e15, element0 [symbolic = %impl.elem0.loc21_11.2 (constants.%impl.elem0.168)]
- // CHECK:STDOUT: %bound_method.loc21_11.1: <bound method> = bound_method %.loc21_11.4, %impl.elem0.loc21_11.1
- // CHECK:STDOUT: %specific_impl_fn.loc21_11.1: <specific function> = specific_impl_function %impl.elem0.loc21_11.1, @Copy.Op(constants.%T.be8) [symbolic = %specific_impl_fn.loc21_11.2 (constants.%specific_impl_fn.2ce)]
- // CHECK:STDOUT: %bound_method.loc21_11.2: <bound method> = bound_method %.loc21_11.4, %specific_impl_fn.loc21_11.1
- // CHECK:STDOUT: <elided>
- // CHECK:STDOUT: %.loc21_11.5: init @AccessBase.%T.binding.as_type (%T.binding.as_type) = call %bound_method.loc21_11.2(%.loc21_11.4) to %.loc19_45
- // CHECK:STDOUT: return %.loc21_11.5 to %return
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: specific @AccessDerived(constants.%T.be8) {
- // CHECK:STDOUT: %T.loc13_18.1 => constants.%T.be8
- // CHECK:STDOUT: %T.binding.as_type => constants.%T.binding.as_type
- // CHECK:STDOUT: %Derived.loc13_45.1 => constants.%Derived.b36
- // CHECK:STDOUT: %pattern_type.loc13_33 => constants.%pattern_type.50f
- // CHECK:STDOUT: %pattern_type.loc13_48 => constants.%pattern_type.17e4b7.1
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: specific @AccessBase(constants.%T.be8) {
- // CHECK:STDOUT: %T.loc19_15.1 => constants.%T.be8
- // CHECK:STDOUT: %T.binding.as_type => constants.%T.binding.as_type
- // CHECK:STDOUT: %Derived.loc19_42.1 => constants.%Derived.b36
- // CHECK:STDOUT: %pattern_type.loc19_30 => constants.%pattern_type.50f
- // CHECK:STDOUT: %pattern_type.loc19_45 => constants.%pattern_type.17e4b7.1
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|