| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- // 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
- //
- // AUTOUPDATE
- // TIP: To test this file alone, run:
- // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/operators/overloaded/fail_assign_non_ref.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/fail_assign_non_ref.carbon
- package User;
- class C {};
- impl C as Core.Inc {
- fn Op[addr self: C*]();
- }
- impl C as Core.AddAssign {
- fn Op[addr self: C*](other: C);
- }
- fn TestIncNonRef(a: C) {
- // CHECK:STDERR: fail_assign_non_ref.carbon:[[@LINE+7]]:5: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef]
- // CHECK:STDERR: ++a;
- // CHECK:STDERR: ^
- // CHECK:STDERR: fail_assign_non_ref.carbon:[[@LINE-10]]:9: note: initializing function parameter [InCallToFunctionParam]
- // CHECK:STDERR: fn Op[addr self: C*]();
- // CHECK:STDERR: ^~~~~~~~~~~~~
- // CHECK:STDERR:
- ++a;
- }
- fn TestAddAssignNonRef(a: C, b: C) {
- // CHECK:STDERR: fail_assign_non_ref.carbon:[[@LINE+7]]:3: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef]
- // CHECK:STDERR: a += b;
- // CHECK:STDERR: ^
- // CHECK:STDERR: fail_assign_non_ref.carbon:[[@LINE-18]]:9: note: initializing function parameter [InCallToFunctionParam]
- // CHECK:STDERR: fn Op[addr self: C*](other: C);
- // CHECK:STDERR: ^~~~~~~~~~~~~
- // CHECK:STDERR:
- a += b;
- }
- // CHECK:STDOUT: --- fail_assign_non_ref.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %C: type = class_type @C [concrete]
- // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
- // CHECK:STDOUT: %Inc.type: type = facet_type <@Inc> [concrete]
- // CHECK:STDOUT: %Op.type.e3a: type = fn_type @Op.1 [concrete]
- // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
- // CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
- // CHECK:STDOUT: %Inc.impl_witness: <witness> = impl_witness file.%Inc.impl_witness_table [concrete]
- // CHECK:STDOUT: %ptr.019: type = ptr_type %C [concrete]
- // CHECK:STDOUT: %pattern_type.44a: type = pattern_type %ptr.019 [concrete]
- // CHECK:STDOUT: %Op.type.73a: type = fn_type @Op.2 [concrete]
- // CHECK:STDOUT: %Op.0c9: %Op.type.73a = struct_value () [concrete]
- // CHECK:STDOUT: %Inc.facet: %Inc.type = facet_value %C, (%Inc.impl_witness) [concrete]
- // CHECK:STDOUT: %AddAssign.type: type = facet_type <@AddAssign> [concrete]
- // CHECK:STDOUT: %Op.type.421: type = fn_type @Op.3 [concrete]
- // CHECK:STDOUT: %AddAssign.impl_witness: <witness> = impl_witness file.%AddAssign.impl_witness_table [concrete]
- // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
- // CHECK:STDOUT: %Op.type.0b8: type = fn_type @Op.4 [concrete]
- // CHECK:STDOUT: %Op.d8e: %Op.type.0b8 = struct_value () [concrete]
- // CHECK:STDOUT: %AddAssign.facet: %AddAssign.type = facet_value %C, (%AddAssign.impl_witness) [concrete]
- // CHECK:STDOUT: %TestIncNonRef.type: type = fn_type @TestIncNonRef [concrete]
- // CHECK:STDOUT: %TestIncNonRef: %TestIncNonRef.type = struct_value () [concrete]
- // CHECK:STDOUT: %.bc7: type = fn_type_with_self_type %Op.type.e3a, %Inc.facet [concrete]
- // CHECK:STDOUT: %TestAddAssignNonRef.type: type = fn_type @TestAddAssignNonRef [concrete]
- // CHECK:STDOUT: %TestAddAssignNonRef: %TestAddAssignNonRef.type = struct_value () [concrete]
- // CHECK:STDOUT: %.6d3: type = fn_type_with_self_type %Op.type.421, %AddAssign.facet [concrete]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
- // CHECK:STDOUT: .Inc = %Core.Inc
- // CHECK:STDOUT: .AddAssign = %Core.AddAssign
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.Inc: type = import_ref Core//prelude/operators/arithmetic, Inc, loaded [concrete = constants.%Inc.type]
- // CHECK:STDOUT: %Core.AddAssign: type = import_ref Core//prelude/operators/arithmetic, AddAssign, loaded [concrete = constants.%AddAssign.type]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .C = %C.decl
- // CHECK:STDOUT: .TestIncNonRef = %TestIncNonRef.decl
- // CHECK:STDOUT: .TestAddAssignNonRef = %TestAddAssignNonRef.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
- // CHECK:STDOUT: impl_decl @impl.c51 [concrete] {} {
- // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
- // CHECK:STDOUT: %Inc.ref: type = name_ref Inc, imports.%Core.Inc [concrete = constants.%Inc.type]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Inc.impl_witness_table = impl_witness_table (@impl.c51.%Op.decl), @impl.c51 [concrete]
- // CHECK:STDOUT: %Inc.impl_witness: <witness> = impl_witness %Inc.impl_witness_table [concrete = constants.%Inc.impl_witness]
- // CHECK:STDOUT: impl_decl @impl.14c [concrete] {} {
- // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
- // CHECK:STDOUT: %AddAssign.ref: type = name_ref AddAssign, imports.%Core.AddAssign [concrete = constants.%AddAssign.type]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %AddAssign.impl_witness_table = impl_witness_table (@impl.14c.%Op.decl), @impl.14c [concrete]
- // CHECK:STDOUT: %AddAssign.impl_witness: <witness> = impl_witness %AddAssign.impl_witness_table [concrete = constants.%AddAssign.impl_witness]
- // CHECK:STDOUT: %TestIncNonRef.decl: %TestIncNonRef.type = fn_decl @TestIncNonRef [concrete = constants.%TestIncNonRef] {
- // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
- // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %a.param: %C = value_param call_param0
- // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %a: %C = bind_name a, %a.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %TestAddAssignNonRef.decl: %TestAddAssignNonRef.type = fn_decl @TestAddAssignNonRef [concrete = constants.%TestAddAssignNonRef] {
- // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
- // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
- // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
- // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param1 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %a.param: %C = value_param call_param0
- // CHECK:STDOUT: %C.ref.loc33_27: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %a: %C = bind_name a, %a.param
- // CHECK:STDOUT: %b.param: %C = value_param call_param1
- // CHECK:STDOUT: %C.ref.loc33_33: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %b: %C = bind_name b, %b.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: impl @impl.c51: %C.ref as %Inc.ref {
- // CHECK:STDOUT: %Op.decl: %Op.type.73a = fn_decl @Op.2 [concrete = constants.%Op.0c9] {
- // CHECK:STDOUT: %self.patt: %pattern_type.44a = binding_pattern self [concrete]
- // CHECK:STDOUT: %self.param_patt: %pattern_type.44a = value_param_pattern %self.patt, call_param0 [concrete]
- // CHECK:STDOUT: %.loc16_9: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %self.param: %ptr.019 = value_param call_param0
- // CHECK:STDOUT: %.loc16_21: type = splice_block %ptr [concrete = constants.%ptr.019] {
- // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %ptr: type = ptr_type %C.ref [concrete = constants.%ptr.019]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %self: %ptr.019 = bind_name self, %self.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .C = <poisoned>
- // CHECK:STDOUT: .Op = %Op.decl
- // CHECK:STDOUT: witness = file.%Inc.impl_witness
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: impl @impl.14c: %C.ref as %AddAssign.ref {
- // CHECK:STDOUT: %Op.decl: %Op.type.0b8 = fn_decl @Op.4 [concrete = constants.%Op.d8e] {
- // CHECK:STDOUT: %self.patt: %pattern_type.44a = binding_pattern self [concrete]
- // CHECK:STDOUT: %self.param_patt: %pattern_type.44a = value_param_pattern %self.patt, call_param0 [concrete]
- // CHECK:STDOUT: %.loc19_9: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
- // CHECK:STDOUT: %other.patt: %pattern_type.c48 = binding_pattern other [concrete]
- // CHECK:STDOUT: %other.param_patt: %pattern_type.c48 = value_param_pattern %other.patt, call_param1 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %self.param: %ptr.019 = value_param call_param0
- // CHECK:STDOUT: %.loc19_21: type = splice_block %ptr [concrete = constants.%ptr.019] {
- // CHECK:STDOUT: %C.ref.loc19_20: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %ptr: type = ptr_type %C.ref.loc19_20 [concrete = constants.%ptr.019]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %self: %ptr.019 = bind_name self, %self.param
- // CHECK:STDOUT: %other.param: %C = value_param call_param1
- // CHECK:STDOUT: %C.ref.loc19_31: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %other: %C = bind_name other, %other.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .C = <poisoned>
- // CHECK:STDOUT: .Op = %Op.decl
- // CHECK:STDOUT: witness = file.%AddAssign.impl_witness
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @C {
- // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%C
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Op.2(%self.param: %ptr.019);
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Op.4(%self.param: %ptr.019, %other.param: %C);
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @TestIncNonRef(%a.param: %C) {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
- // CHECK:STDOUT: %impl.elem0: %.bc7 = impl_witness_access constants.%Inc.impl_witness, element0 [concrete = constants.%Op.0c9]
- // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
- // CHECK:STDOUT: %.loc30: ref %C = temporary_storage
- // CHECK:STDOUT: %addr: %ptr.019 = addr_of %.loc30
- // CHECK:STDOUT: %Op.call: init %empty_tuple.type = call %bound_method(%addr)
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @TestAddAssignNonRef(%a.param: %C, %b.param: %C) {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
- // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
- // CHECK:STDOUT: %impl.elem0: %.6d3 = impl_witness_access constants.%AddAssign.impl_witness, element0 [concrete = constants.%Op.d8e]
- // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
- // CHECK:STDOUT: %.loc41: ref %C = temporary_storage
- // CHECK:STDOUT: %addr: %ptr.019 = addr_of %.loc41
- // CHECK:STDOUT: %Op.call: init %empty_tuple.type = call %bound_method(%addr, %b.ref)
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|