generic_method.carbon 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_method.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic_method.carbon
  10. class Class(T:! type) {
  11. var a: T;
  12. fn F[self: Self](n: T);
  13. }
  14. fn Class(T:! type).F[self: Self](n: T) {}
  15. // CHECK:STDOUT: --- generic_method.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  19. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  20. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  21. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  22. // CHECK:STDOUT: %Class.2: type = class_type @Class, (%T) [symbolic]
  23. // CHECK:STDOUT: %.2: type = unbound_element_type %Class.2, %T [symbolic]
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  26. // CHECK:STDOUT: %.3: type = struct_type {.a: %T} [symbolic]
  27. // CHECK:STDOUT: %.4: type = ptr_type %.3 [symbolic]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: file {
  31. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  32. // CHECK:STDOUT: .Core = %Core
  33. // CHECK:STDOUT: .Class = %Class.decl
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  36. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  37. // CHECK:STDOUT: %T.loc11_13.1: type = param T
  38. // CHECK:STDOUT: %T.loc11_13.2: type = bind_symbolic_name T 0, %T.loc11_13.1 [symbolic = constants.%T]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  41. // CHECK:STDOUT: %T.loc16_10.1: type = param T
  42. // CHECK:STDOUT: %T.loc16_10.2: type = bind_symbolic_name T 0, %T.loc16_10.1 [symbolic = constants.%T]
  43. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Class.2 [symbolic = constants.%Class.2]
  44. // CHECK:STDOUT: %self.loc16_22.1: %Class.2 = param self
  45. // CHECK:STDOUT: @F.%self: %Class.2 = bind_name self, %self.loc16_22.1
  46. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc16_10.2 [symbolic = constants.%T]
  47. // CHECK:STDOUT: %n.loc16_34.1: %T = param n
  48. // CHECK:STDOUT: @F.%n: %T = bind_name n, %n.loc16_34.1
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: class @Class
  53. // CHECK:STDOUT: generic [file.%T.loc11_13.2: type] {
  54. // CHECK:STDOUT: %T.ref.loc12: type = name_ref T, file.%T.loc11_13.2 [symbolic = constants.%T]
  55. // CHECK:STDOUT: %.loc12: %.2 = field_decl a, element0 [template]
  56. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  57. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Class.2 [symbolic = constants.%Class.2]
  58. // CHECK:STDOUT: %self.loc13_8.1: %Class.2 = param self
  59. // CHECK:STDOUT: %self.loc13_8.2: %Class.2 = bind_name self, %self.loc13_8.1
  60. // CHECK:STDOUT: %T.ref.loc13: type = name_ref T, file.%T.loc11_13.2 [symbolic = constants.%T]
  61. // CHECK:STDOUT: %n.loc13_20.1: %T = param n
  62. // CHECK:STDOUT: %n.loc13_20.2: %T = bind_name n, %n.loc13_20.1
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: !members:
  66. // CHECK:STDOUT: .Self = constants.%Class.2
  67. // CHECK:STDOUT: .a = %.loc12
  68. // CHECK:STDOUT: .F = %F.decl
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @F[%self: %Class.2](%n: %T)
  72. // CHECK:STDOUT: generic [file.%T.loc11_13.2: type] {
  73. // CHECK:STDOUT: !entry:
  74. // CHECK:STDOUT: return
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: