fail_todo_use.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/generic/fail_todo_use.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/fail_todo_use.carbon
  10. class Class(T:! type) {
  11. fn Get[addr self: Self*]() -> T* {
  12. return &self->k;
  13. }
  14. var k: T;
  15. }
  16. // TODO: The following should work.
  17. fn Run() -> i32 {
  18. // CHECK:STDERR: fail_todo_use.carbon:[[@LINE+4]]:23: ERROR: Cannot implicitly convert from `i32` to `T`.
  19. // CHECK:STDERR: var v: Class(i32) = {.k = 0};
  20. // CHECK:STDERR: ^~~~~~~~
  21. // CHECK:STDERR:
  22. var v: Class(i32) = {.k = 0};
  23. // CHECK:STDERR: fail_todo_use.carbon:[[@LINE+10]]:3: ERROR: Cannot implicitly convert from `T*` to `i32`.
  24. // CHECK:STDERR: return v.Get();
  25. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  26. // CHECK:STDERR:
  27. // CHECK:STDERR: fail_todo_use.carbon:[[@LINE+6]]:10: ERROR: Cannot implicitly convert from `Class*` to `Class*`.
  28. // CHECK:STDERR: return v.Get();
  29. // CHECK:STDERR: ^~~~~~
  30. // CHECK:STDERR: fail_todo_use.carbon:[[@LINE-21]]:15: Initializing `addr self` parameter of method declared here.
  31. // CHECK:STDERR: fn Get[addr self: Self*]() -> T* {
  32. // CHECK:STDERR: ^~~~
  33. return v.Get();
  34. }
  35. // CHECK:STDOUT: --- fail_todo_use.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  39. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  40. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  41. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  42. // CHECK:STDOUT: %Class.2: type = class_type @Class, (%T) [symbolic]
  43. // CHECK:STDOUT: %.2: type = ptr_type %Class.2 [symbolic]
  44. // CHECK:STDOUT: %.3: type = ptr_type %T [symbolic]
  45. // CHECK:STDOUT: %Get.type: type = fn_type @Get [template]
  46. // CHECK:STDOUT: %Get: %Get.type = struct_value () [template]
  47. // CHECK:STDOUT: %.4: type = unbound_element_type %Class.2, %T [symbolic]
  48. // CHECK:STDOUT: %.5: type = struct_type {.k: %T} [symbolic]
  49. // CHECK:STDOUT: %.6: type = ptr_type %.5 [symbolic]
  50. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  51. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  52. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  53. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  54. // CHECK:STDOUT: %Class.3: type = class_type @Class, (i32) [template]
  55. // CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
  56. // CHECK:STDOUT: %.8: type = struct_type {.k: i32} [template]
  57. // CHECK:STDOUT: %.9: type = ptr_type %Class.3 [template]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: file {
  61. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  62. // CHECK:STDOUT: .Core = %Core
  63. // CHECK:STDOUT: .Class = %Class.decl
  64. // CHECK:STDOUT: .Run = %Run.decl
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  67. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  68. // CHECK:STDOUT: %T.loc11_13.1: type = param T
  69. // CHECK:STDOUT: %T.loc11_13.2: type = bind_symbolic_name T 0, %T.loc11_13.1 [symbolic = constants.%T]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  72. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {
  73. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  74. // CHECK:STDOUT: %.loc20_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  75. // CHECK:STDOUT: %.loc20_13.2: type = converted %int.make_type_32, %.loc20_13.1 [template = i32]
  76. // CHECK:STDOUT: @Run.%return: ref i32 = var <return slot>
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: class @Class
  82. // CHECK:STDOUT: generic [file.%T.loc11_13.2: type] {
  83. // CHECK:STDOUT: %Get.decl: %Get.type = fn_decl @Get [template = constants.%Get] {
  84. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Class.2 [symbolic = constants.%Class.2]
  85. // CHECK:STDOUT: %.loc12_25: type = ptr_type %Class.2 [symbolic = constants.%.2]
  86. // CHECK:STDOUT: %self.loc12_15.1: %.2 = param self
  87. // CHECK:STDOUT: %self.loc12_15.3: %.2 = bind_name self, %self.loc12_15.1
  88. // CHECK:STDOUT: %.loc12_10: %.2 = addr_pattern %self.loc12_15.3
  89. // CHECK:STDOUT: %T.ref.loc12: type = name_ref T, file.%T.loc11_13.2 [symbolic = constants.%T]
  90. // CHECK:STDOUT: %.loc12_34: type = ptr_type %T [symbolic = constants.%.3]
  91. // CHECK:STDOUT: %return.var: ref %.3 = var <return slot>
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %T.ref.loc16: type = name_ref T, file.%T.loc11_13.2 [symbolic = constants.%T]
  94. // CHECK:STDOUT: %.loc16: %.4 = field_decl k, element0 [template]
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: !members:
  97. // CHECK:STDOUT: .Self = constants.%Class.2
  98. // CHECK:STDOUT: .Get = %Get.decl
  99. // CHECK:STDOUT: .k = %.loc16
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @Get[addr @Class.%self.loc12_15.3: %.2]() -> %.3
  103. // CHECK:STDOUT: generic [file.%T.loc11_13.2: type] {
  104. // CHECK:STDOUT: !entry:
  105. // CHECK:STDOUT: %self.ref: %.2 = name_ref self, @Class.%self.loc12_15.3
  106. // CHECK:STDOUT: %.loc13_17.1: ref %Class.2 = deref %self.ref
  107. // CHECK:STDOUT: %k.ref: %.4 = name_ref k, @Class.%.loc16 [template = @Class.%.loc16]
  108. // CHECK:STDOUT: %.loc13_17.2: ref %T = class_element_access %.loc13_17.1, element0
  109. // CHECK:STDOUT: %.loc13_12: %.3 = addr_of %.loc13_17.2
  110. // CHECK:STDOUT: return %.loc13_12
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @Run() -> i32 {
  116. // CHECK:STDOUT: !entry:
  117. // CHECK:STDOUT: %Class.ref: %Class.type = name_ref Class, file.%Class.decl [template = constants.%Class.1]
  118. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  119. // CHECK:STDOUT: %.loc25_15.1: type = value_of_initializer %int.make_type_32 [template = i32]
  120. // CHECK:STDOUT: %.loc25_15.2: type = converted %int.make_type_32, %.loc25_15.1 [template = i32]
  121. // CHECK:STDOUT: %.loc25_15.3: init type = call %Class.ref(%.loc25_15.2) [template = constants.%Class.3]
  122. // CHECK:STDOUT: %.loc25_19.1: type = value_of_initializer %.loc25_15.3 [template = constants.%Class.3]
  123. // CHECK:STDOUT: %.loc25_19.2: type = converted %.loc25_15.3, %.loc25_19.1 [template = constants.%Class.3]
  124. // CHECK:STDOUT: %v.var: ref %Class.3 = var v
  125. // CHECK:STDOUT: %v: ref %Class.3 = bind_name v, %v.var
  126. // CHECK:STDOUT: %.loc25_29: i32 = int_literal 0 [template = constants.%.7]
  127. // CHECK:STDOUT: %.loc25_30: %.8 = struct_literal (%.loc25_29)
  128. // CHECK:STDOUT: assign %v.var, <error>
  129. // CHECK:STDOUT: %v.ref: ref %Class.3 = name_ref v, %v
  130. // CHECK:STDOUT: %Get.ref: %Get.type = name_ref Get, @Class.%Get.decl [template = constants.%Get]
  131. // CHECK:STDOUT: %.loc36_11: <bound method> = bound_method %v.ref, %Get.ref
  132. // CHECK:STDOUT: %.loc36_10: %.9 = addr_of %v.ref
  133. // CHECK:STDOUT: %Get.call: init %.3 = call %.loc36_11(<invalid>) [template = <error>]
  134. // CHECK:STDOUT: return <error>
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: