| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- // 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/full.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/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[ref self: C]();
- }
- impl C as Core.AddAssignWith(C) {
- fn Op[ref self: C](other: C);
- }
- fn TestIncNonRef(a: C) {
- // CHECK:STDERR: fail_assign_non_ref.carbon:[[@LINE+7]]:5: error: value expression passed to reference parameter [ValueForRefParam]
- // CHECK:STDERR: ++a;
- // CHECK:STDERR: ^
- // CHECK:STDERR: fail_assign_non_ref.carbon:[[@LINE-10]]:9: note: initializing function parameter [InCallToFunctionParam]
- // CHECK:STDERR: fn Op[ref self: C]();
- // CHECK:STDERR: ^~~~~~~~~~~
- // CHECK:STDERR:
- ++a;
- }
- fn TestAddAssignNonRef(a: C, b: C) {
- // CHECK:STDERR: fail_assign_non_ref.carbon:[[@LINE+7]]:3: error: value expression passed to reference parameter [ValueForRefParam]
- // 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[ref 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: %Inc.impl_witness: <witness> = impl_witness @C.as.Inc.impl.%Inc.impl_witness_table [concrete]
- // CHECK:STDOUT: %pattern_type.476: type = pattern_type %C [concrete]
- // CHECK:STDOUT: %C.as.Inc.impl.Op.type: type = fn_type @C.as.Inc.impl.Op [concrete]
- // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
- // CHECK:STDOUT: %C.as.Inc.impl.Op: %C.as.Inc.impl.Op.type = struct_value () [concrete]
- // CHECK:STDOUT: %Inc.facet: %Inc.type = facet_value %C, (%Inc.impl_witness) [concrete]
- // CHECK:STDOUT: %Inc.WithSelf.Op.type.700: type = fn_type @Inc.WithSelf.Op, @Inc.WithSelf(%Inc.facet) [concrete]
- // CHECK:STDOUT: %AddAssignWith.type.fc6: type = generic_interface_type @AddAssignWith [concrete]
- // CHECK:STDOUT: %AddAssignWith.generic: %AddAssignWith.type.fc6 = struct_value () [concrete]
- // CHECK:STDOUT: %AddAssignWith.type.16b: type = facet_type <@AddAssignWith, @AddAssignWith(%C)> [concrete]
- // CHECK:STDOUT: %AddAssignWith.impl_witness: <witness> = impl_witness @C.as.AddAssignWith.impl.%AddAssignWith.impl_witness_table [concrete]
- // CHECK:STDOUT: %C.as.AddAssignWith.impl.Op.type: type = fn_type @C.as.AddAssignWith.impl.Op [concrete]
- // CHECK:STDOUT: %C.as.AddAssignWith.impl.Op: %C.as.AddAssignWith.impl.Op.type = struct_value () [concrete]
- // CHECK:STDOUT: %AddAssignWith.facet: %AddAssignWith.type.16b = facet_value %C, (%AddAssignWith.impl_witness) [concrete]
- // CHECK:STDOUT: %AddAssignWith.WithSelf.Op.type.2b1: type = fn_type @AddAssignWith.WithSelf.Op, @AddAssignWith.WithSelf(%C, %AddAssignWith.facet) [concrete]
- // CHECK:STDOUT: %TestIncNonRef.type: type = fn_type @TestIncNonRef [concrete]
- // CHECK:STDOUT: %TestIncNonRef: %TestIncNonRef.type = struct_value () [concrete]
- // CHECK:STDOUT: %.38a: type = fn_type_with_self_type %Inc.WithSelf.Op.type.700, %Inc.facet [concrete]
- // CHECK:STDOUT: %TestAddAssignNonRef.type: type = fn_type @TestAddAssignNonRef [concrete]
- // CHECK:STDOUT: %TestAddAssignNonRef: %TestAddAssignNonRef.type = struct_value () [concrete]
- // CHECK:STDOUT: %.168: type = fn_type_with_self_type %AddAssignWith.WithSelf.Op.type.2b1, %AddAssignWith.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: .AddAssignWith = %Core.AddAssignWith
- // 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.AddAssignWith: %AddAssignWith.type.fc6 = import_ref Core//prelude/operators/arithmetic, AddAssignWith, loaded [concrete = constants.%AddAssignWith.generic]
- // 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 @C.as.Inc.impl [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: impl_decl @C.as.AddAssignWith.impl [concrete] {} {
- // CHECK:STDOUT: %C.ref.loc22_6: 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: %AddAssignWith.ref: %AddAssignWith.type.fc6 = name_ref AddAssignWith, imports.%Core.AddAssignWith [concrete = constants.%AddAssignWith.generic]
- // CHECK:STDOUT: %C.ref.loc22_30: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %AddAssignWith.type: type = facet_type <@AddAssignWith, @AddAssignWith(constants.%C)> [concrete = constants.%AddAssignWith.type.16b]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %TestIncNonRef.decl: %TestIncNonRef.type = fn_decl @TestIncNonRef [concrete = constants.%TestIncNonRef] {
- // CHECK:STDOUT: %a.param_patt: %pattern_type.476 = value_param_pattern [concrete]
- // CHECK:STDOUT: %a.patt: %pattern_type.476 = at_binding_pattern a, %a.param_patt [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 = value_binding a, %a.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %TestAddAssignNonRef.decl: %TestAddAssignNonRef.type = fn_decl @TestAddAssignNonRef [concrete = constants.%TestAddAssignNonRef] {
- // CHECK:STDOUT: %a.param_patt: %pattern_type.476 = value_param_pattern [concrete]
- // CHECK:STDOUT: %a.patt: %pattern_type.476 = at_binding_pattern a, %a.param_patt [concrete]
- // CHECK:STDOUT: %b.param_patt: %pattern_type.476 = value_param_pattern [concrete]
- // CHECK:STDOUT: %b.patt: %pattern_type.476 = at_binding_pattern b, %b.param_patt [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %a.param: %C = value_param call_param0
- // CHECK:STDOUT: %C.ref.loc37_27: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %a: %C = value_binding a, %a.param
- // CHECK:STDOUT: %b.param: %C = value_param call_param1
- // CHECK:STDOUT: %C.ref.loc37_33: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %b: %C = value_binding b, %b.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: impl @C.as.Inc.impl: %C.ref as %Inc.ref {
- // CHECK:STDOUT: %C.as.Inc.impl.Op.decl: %C.as.Inc.impl.Op.type = fn_decl @C.as.Inc.impl.Op [concrete = constants.%C.as.Inc.impl.Op] {
- // CHECK:STDOUT: %self.param_patt: %pattern_type.476 = ref_param_pattern [concrete]
- // CHECK:STDOUT: %self.patt: %pattern_type.476 = at_binding_pattern self, %self.param_patt [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %self.param: ref %C = ref_param call_param0
- // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %self: ref %C = ref_binding self, %self.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Inc.impl_witness_table = impl_witness_table (%C.as.Inc.impl.Op.decl), @C.as.Inc.impl [concrete]
- // CHECK:STDOUT: %Inc.impl_witness: <witness> = impl_witness %Inc.impl_witness_table [concrete = constants.%Inc.impl_witness]
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .C = <poisoned>
- // CHECK:STDOUT: .Op = %C.as.Inc.impl.Op.decl
- // CHECK:STDOUT: witness = %Inc.impl_witness
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: impl @C.as.AddAssignWith.impl: %C.ref.loc22_6 as %AddAssignWith.type {
- // CHECK:STDOUT: %C.as.AddAssignWith.impl.Op.decl: %C.as.AddAssignWith.impl.Op.type = fn_decl @C.as.AddAssignWith.impl.Op [concrete = constants.%C.as.AddAssignWith.impl.Op] {
- // CHECK:STDOUT: %self.param_patt: %pattern_type.476 = ref_param_pattern [concrete]
- // CHECK:STDOUT: %self.patt: %pattern_type.476 = at_binding_pattern self, %self.param_patt [concrete]
- // CHECK:STDOUT: %other.param_patt: %pattern_type.476 = value_param_pattern [concrete]
- // CHECK:STDOUT: %other.patt: %pattern_type.476 = at_binding_pattern other, %other.param_patt [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %self.param: ref %C = ref_param call_param0
- // CHECK:STDOUT: %C.ref.loc23_19: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %self: ref %C = ref_binding self, %self.param
- // CHECK:STDOUT: %other.param: %C = value_param call_param1
- // CHECK:STDOUT: %C.ref.loc23_29: type = name_ref C, file.%C.decl [concrete = constants.%C]
- // CHECK:STDOUT: %other: %C = value_binding other, %other.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %AddAssignWith.impl_witness_table = impl_witness_table (%C.as.AddAssignWith.impl.Op.decl), @C.as.AddAssignWith.impl [concrete]
- // CHECK:STDOUT: %AddAssignWith.impl_witness: <witness> = impl_witness %AddAssignWith.impl_witness_table [concrete = constants.%AddAssignWith.impl_witness]
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .C = <poisoned>
- // CHECK:STDOUT: .Op = %C.as.AddAssignWith.impl.Op.decl
- // CHECK:STDOUT: witness = %AddAssignWith.impl_witness
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @C {
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%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 @C.as.Inc.impl.Op(%self.param: ref %C);
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @C.as.AddAssignWith.impl.Op(%self.param: ref %C, %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: %.38a = impl_witness_access constants.%Inc.impl_witness, element0 [concrete = constants.%C.as.Inc.impl.Op]
- // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
- // CHECK:STDOUT: %C.as.Inc.impl.Op.call: init %empty_tuple.type = call %bound_method(<error>)
- // 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: %.168 = impl_witness_access constants.%AddAssignWith.impl_witness, element0 [concrete = constants.%C.as.AddAssignWith.impl.Op]
- // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
- // CHECK:STDOUT: %C.as.AddAssignWith.impl.Op.call: init %empty_tuple.type = call %bound_method(<error>, %b.ref)
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|