fail_todo_self_in_signature.carbon 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. interface UseSelf {
  7. fn F[self: Self](x: Self) -> Self;
  8. }
  9. class C {}
  10. impl C as UseSelf {
  11. // TODO: Use `Self` below once it's supported.
  12. // CHECK:STDERR: fail_todo_self_in_signature.carbon:[[@LINE+6]]:8: ERROR: Function redeclaration differs at implicit parameter 1.
  13. // CHECK:STDERR: fn F[self: C](x: C) -> C { return {}; }
  14. // CHECK:STDERR: ^~~~
  15. // CHECK:STDERR: fail_todo_self_in_signature.carbon:[[@LINE-10]]:8: Previous declaration's corresponding implicit parameter here.
  16. // CHECK:STDERR: fn F[self: Self](x: Self) -> Self;
  17. // CHECK:STDERR: ^~~~
  18. fn F[self: C](x: C) -> C { return {}; }
  19. }
  20. // CHECK:STDOUT: --- fail_todo_self_in_signature.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %.1: type = interface_type @UseSelf [template]
  24. // CHECK:STDOUT: %.2: type = assoc_entity_type @UseSelf, <function> [template]
  25. // CHECK:STDOUT: %.3: <associated <function> in UseSelf> = assoc_entity element0, @UseSelf.%F [template]
  26. // CHECK:STDOUT: %C: type = class_type @C [template]
  27. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  28. // CHECK:STDOUT: %.5: type = tuple_type () [template]
  29. // CHECK:STDOUT: %.6: type = ptr_type {} [template]
  30. // CHECK:STDOUT: %.7: C = struct_value () [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: file {
  34. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  35. // CHECK:STDOUT: .UseSelf = %UseSelf.decl
  36. // CHECK:STDOUT: .C = %C.decl
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %UseSelf.decl: type = interface_decl @UseSelf [template = constants.%.1] {}
  39. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  40. // CHECK:STDOUT: impl_decl @impl {
  41. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  42. // CHECK:STDOUT: %UseSelf.ref: type = name_ref UseSelf, %UseSelf.decl [template = constants.%.1]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: interface @UseSelf {
  47. // CHECK:STDOUT: %Self: UseSelf = bind_symbolic_name Self [symbolic]
  48. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {
  49. // CHECK:STDOUT: %Self.ref.loc8_14: UseSelf = name_ref Self, %Self [symbolic = %Self]
  50. // CHECK:STDOUT: %.loc8_14.1: type = facet_type_access %Self.ref.loc8_14 [symbolic = %Self]
  51. // CHECK:STDOUT: %.loc8_14.2: type = converted %Self.ref.loc8_14, %.loc8_14.1 [symbolic = %Self]
  52. // CHECK:STDOUT: %self.loc8_8.1: Self = param self
  53. // CHECK:STDOUT: %self.loc8_8.2: Self = bind_name self, %self.loc8_8.1
  54. // CHECK:STDOUT: %Self.ref.loc8_23: UseSelf = name_ref Self, %Self [symbolic = %Self]
  55. // CHECK:STDOUT: %.loc8_23.1: type = facet_type_access %Self.ref.loc8_23 [symbolic = %Self]
  56. // CHECK:STDOUT: %.loc8_23.2: type = converted %Self.ref.loc8_23, %.loc8_23.1 [symbolic = %Self]
  57. // CHECK:STDOUT: %x.loc8_20.1: Self = param x
  58. // CHECK:STDOUT: %x.loc8_20.2: Self = bind_name x, %x.loc8_20.1
  59. // CHECK:STDOUT: %Self.ref.loc8_32: UseSelf = name_ref Self, %Self [symbolic = %Self]
  60. // CHECK:STDOUT: %.loc8_32.1: type = facet_type_access %Self.ref.loc8_32 [symbolic = %Self]
  61. // CHECK:STDOUT: %.loc8_32.2: type = converted %Self.ref.loc8_32, %.loc8_32.1 [symbolic = %Self]
  62. // CHECK:STDOUT: %return.var: ref Self = var <return slot>
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %.loc8_36: <associated <function> in UseSelf> = assoc_entity element0, %F [template = constants.%.3]
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: !members:
  67. // CHECK:STDOUT: .Self = %Self
  68. // CHECK:STDOUT: .F = %.loc8_36
  69. // CHECK:STDOUT: witness = (%F)
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: impl @impl: C as UseSelf {
  73. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {
  74. // CHECK:STDOUT: %C.ref.loc21_14: type = name_ref C, file.%C.decl [template = constants.%C]
  75. // CHECK:STDOUT: %self.loc21_8.1: C = param self
  76. // CHECK:STDOUT: %self.loc21_8.2: C = bind_name self, %self.loc21_8.1
  77. // CHECK:STDOUT: %C.ref.loc21_20: type = name_ref C, file.%C.decl [template = constants.%C]
  78. // CHECK:STDOUT: %x.loc21_17.1: C = param x
  79. // CHECK:STDOUT: %x.loc21_17.2: C = bind_name x, %x.loc21_17.1
  80. // CHECK:STDOUT: %C.ref.loc21_26: type = name_ref C, file.%C.decl [template = constants.%C]
  81. // CHECK:STDOUT: %return.var: ref C = var <return slot>
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %.1: <witness> = interface_witness (<error>) [template = <error>]
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: !members:
  86. // CHECK:STDOUT: .F = %F
  87. // CHECK:STDOUT: witness = %.1
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: class @C {
  91. // CHECK:STDOUT: !members:
  92. // CHECK:STDOUT: .Self = constants.%C
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn @F.1[@UseSelf.%self.loc8_8.2: Self](@UseSelf.%x.loc8_20.2: Self) -> Self;
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @F.2[@impl.%self.loc21_8.2: C](@impl.%x.loc21_17.2: C) -> @impl.%return.var: C {
  98. // CHECK:STDOUT: !entry:
  99. // CHECK:STDOUT: %.loc21_38.1: {} = struct_literal ()
  100. // CHECK:STDOUT: %.loc21_38.2: init C = class_init (), @impl.%return.var [template = constants.%.7]
  101. // CHECK:STDOUT: %.loc21_38.3: init C = converted %.loc21_38.1, %.loc21_38.2 [template = constants.%.7]
  102. // CHECK:STDOUT: return %.loc21_38.3
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: