| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- // 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/class/generic/fail_todo_use.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/fail_todo_use.carbon
- class Class(T:! type) {
- fn Get[addr self: Self*]() -> T* {
- return &self->k;
- }
- var k: T;
- }
- // TODO: The following should work.
- fn Run() -> i32 {
- // CHECK:STDERR: fail_todo_use.carbon:[[@LINE+4]]:23: ERROR: Cannot implicitly convert from `i32` to `T`.
- // CHECK:STDERR: var v: Class(i32) = {.k = 0};
- // CHECK:STDERR: ^~~~~~~~
- // CHECK:STDERR:
- var v: Class(i32) = {.k = 0};
- // CHECK:STDERR: fail_todo_use.carbon:[[@LINE+10]]:3: ERROR: Cannot implicitly convert from `T*` to `i32`.
- // CHECK:STDERR: return v.Get();
- // CHECK:STDERR: ^~~~~~~~~~~~~~~
- // CHECK:STDERR:
- // CHECK:STDERR: fail_todo_use.carbon:[[@LINE+6]]:10: ERROR: Cannot implicitly convert from `Class*` to `Class*`.
- // CHECK:STDERR: return v.Get();
- // CHECK:STDERR: ^~~~~~
- // CHECK:STDERR: fail_todo_use.carbon:[[@LINE-21]]:15: Initializing `addr self` parameter of method declared here.
- // CHECK:STDERR: fn Get[addr self: Self*]() -> T* {
- // CHECK:STDERR: ^~~~
- return v.Get();
- }
- // CHECK:STDOUT: --- fail_todo_use.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
- // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
- // CHECK:STDOUT: %.1: type = tuple_type () [template]
- // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
- // CHECK:STDOUT: %Class.2: type = class_type @Class, (%T) [symbolic]
- // CHECK:STDOUT: %.2: type = ptr_type %Class.2 [symbolic]
- // CHECK:STDOUT: %.3: type = ptr_type %T [symbolic]
- // CHECK:STDOUT: %Get.type: type = fn_type @Get [template]
- // CHECK:STDOUT: %Get: %Get.type = struct_value () [template]
- // CHECK:STDOUT: %.4: type = unbound_element_type %Class.2, %T [symbolic]
- // CHECK:STDOUT: %.5: type = struct_type {.k: %T} [symbolic]
- // CHECK:STDOUT: %.6: type = ptr_type %.5 [symbolic]
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
- // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
- // CHECK:STDOUT: %Class.3: type = class_type @Class, (i32) [template]
- // CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
- // CHECK:STDOUT: %.8: type = struct_type {.k: i32} [template]
- // CHECK:STDOUT: %.9: type = ptr_type %Class.3 [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core
- // CHECK:STDOUT: .Class = %Class.decl
- // CHECK:STDOUT: .Run = %Run.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
- // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
- // CHECK:STDOUT: %T.loc11_13.1: type = param T
- // CHECK:STDOUT: %T.loc11_13.2: type = bind_symbolic_name T 0, %T.loc11_13.1 [symbolic = constants.%T]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
- // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {
- // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
- // CHECK:STDOUT: %.loc20_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
- // CHECK:STDOUT: %.loc20_13.2: type = converted %int.make_type_32, %.loc20_13.1 [template = i32]
- // CHECK:STDOUT: @Run.%return: ref i32 = var <return slot>
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @Class
- // CHECK:STDOUT: generic [file.%T.loc11_13.2: type] {
- // CHECK:STDOUT: %Get.decl: %Get.type = fn_decl @Get [template = constants.%Get] {
- // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Class.2 [symbolic = constants.%Class.2]
- // CHECK:STDOUT: %.loc12_25: type = ptr_type %Class.2 [symbolic = constants.%.2]
- // CHECK:STDOUT: %self.loc12_15.1: %.2 = param self
- // CHECK:STDOUT: %self.loc12_15.3: %.2 = bind_name self, %self.loc12_15.1
- // CHECK:STDOUT: %.loc12_10: %.2 = addr_pattern %self.loc12_15.3
- // CHECK:STDOUT: %T.ref.loc12: type = name_ref T, file.%T.loc11_13.2 [symbolic = constants.%T]
- // CHECK:STDOUT: %.loc12_34: type = ptr_type %T [symbolic = constants.%.3]
- // CHECK:STDOUT: %return.var: ref %.3 = var <return slot>
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %T.ref.loc16: type = name_ref T, file.%T.loc11_13.2 [symbolic = constants.%T]
- // CHECK:STDOUT: %.loc16: %.4 = field_decl k, element0 [template]
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%Class.2
- // CHECK:STDOUT: .Get = %Get.decl
- // CHECK:STDOUT: .k = %.loc16
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Get[addr @Class.%self.loc12_15.3: %.2]() -> %.3
- // CHECK:STDOUT: generic [file.%T.loc11_13.2: type] {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %self.ref: %.2 = name_ref self, @Class.%self.loc12_15.3
- // CHECK:STDOUT: %.loc13_17.1: ref %Class.2 = deref %self.ref
- // CHECK:STDOUT: %k.ref: %.4 = name_ref k, @Class.%.loc16 [template = @Class.%.loc16]
- // CHECK:STDOUT: %.loc13_17.2: ref %T = class_element_access %.loc13_17.1, element0
- // CHECK:STDOUT: %.loc13_12: %.3 = addr_of %.loc13_17.2
- // CHECK:STDOUT: return %.loc13_12
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Run() -> i32 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %Class.ref: %Class.type = name_ref Class, file.%Class.decl [template = constants.%Class.1]
- // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
- // CHECK:STDOUT: %.loc25_15.1: type = value_of_initializer %int.make_type_32 [template = i32]
- // CHECK:STDOUT: %.loc25_15.2: type = converted %int.make_type_32, %.loc25_15.1 [template = i32]
- // CHECK:STDOUT: %.loc25_15.3: init type = call %Class.ref(%.loc25_15.2) [template = constants.%Class.3]
- // CHECK:STDOUT: %.loc25_19.1: type = value_of_initializer %.loc25_15.3 [template = constants.%Class.3]
- // CHECK:STDOUT: %.loc25_19.2: type = converted %.loc25_15.3, %.loc25_19.1 [template = constants.%Class.3]
- // CHECK:STDOUT: %v.var: ref %Class.3 = var v
- // CHECK:STDOUT: %v: ref %Class.3 = bind_name v, %v.var
- // CHECK:STDOUT: %.loc25_29: i32 = int_literal 0 [template = constants.%.7]
- // CHECK:STDOUT: %.loc25_30: %.8 = struct_literal (%.loc25_29)
- // CHECK:STDOUT: assign %v.var, <error>
- // CHECK:STDOUT: %v.ref: ref %Class.3 = name_ref v, %v
- // CHECK:STDOUT: %Get.ref: %Get.type = name_ref Get, @Class.%Get.decl [template = constants.%Get]
- // CHECK:STDOUT: %.loc36_11: <bound method> = bound_method %v.ref, %Get.ref
- // CHECK:STDOUT: %.loc36_10: %.9 = addr_of %v.ref
- // CHECK:STDOUT: %Get.call: init %.3 = call %.loc36_11(<invalid>) [template = <error>]
- // CHECK:STDOUT: return <error>
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|