fail_call_invalid.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/fail_call_invalid.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_call_invalid.carbon
  14. interface Simple {
  15. fn G[self: Self]();
  16. }
  17. impl i32 as Simple {
  18. // CHECK:STDERR: fail_call_invalid.carbon:[[@LINE+4]]:14: error: name `Undeclared` not found [NameNotFound]
  19. // CHECK:STDERR: fn G[self: Undeclared]();
  20. // CHECK:STDERR: ^~~~~~~~~~
  21. // CHECK:STDERR:
  22. fn G[self: Undeclared]();
  23. }
  24. fn InstanceCall(n: i32) {
  25. n.(Simple.G)();
  26. }
  27. // CHECK:STDOUT: --- fail_call_invalid.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple> [concrete]
  31. // CHECK:STDOUT: %Self: %Simple.type = symbolic_binding Self, 0 [symbolic]
  32. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic]
  33. // CHECK:STDOUT: %pattern_type.52e: type = pattern_type %Self.binding.as_type [symbolic]
  34. // CHECK:STDOUT: %Simple.G.type: type = fn_type @Simple.G [concrete]
  35. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  36. // CHECK:STDOUT: %Simple.G: %Simple.G.type = struct_value () [concrete]
  37. // CHECK:STDOUT: %Simple.assoc_type: type = assoc_entity_type @Simple [concrete]
  38. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, @Simple.%Simple.G.decl [concrete]
  39. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  40. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  41. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  42. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  43. // CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness file.%Simple.impl_witness_table [concrete]
  44. // CHECK:STDOUT: %i32.as.Simple.impl.G.type.4745bc.1: type = fn_type @i32.as.Simple.impl.G.loc24_27.1 [concrete]
  45. // CHECK:STDOUT: %i32.as.Simple.impl.G.2bbe53.1: %i32.as.Simple.impl.G.type.4745bc.1 = struct_value () [concrete]
  46. // CHECK:STDOUT: %Simple.facet: %Simple.type = facet_value %i32, (%Simple.impl_witness) [concrete]
  47. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  48. // CHECK:STDOUT: %i32.as.Simple.impl.G.type.4745bc.2: type = fn_type @i32.as.Simple.impl.G.loc24_27.2 [concrete]
  49. // CHECK:STDOUT: %i32.as.Simple.impl.G.2bbe53.2: %i32.as.Simple.impl.G.type.4745bc.2 = struct_value () [concrete]
  50. // CHECK:STDOUT: %InstanceCall.type: type = fn_type @InstanceCall [concrete]
  51. // CHECK:STDOUT: %InstanceCall: %InstanceCall.type = struct_value () [concrete]
  52. // CHECK:STDOUT: %.cb3: type = fn_type_with_self_type %Simple.G.type, %Simple.facet [concrete]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: imports {
  56. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  57. // CHECK:STDOUT: .Int = %Core.Int
  58. // CHECK:STDOUT: import Core//prelude
  59. // CHECK:STDOUT: import Core//prelude/...
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: file {
  65. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  66. // CHECK:STDOUT: .Core = imports.%Core
  67. // CHECK:STDOUT: .Simple = %Simple.decl
  68. // CHECK:STDOUT: .Undeclared = <poisoned>
  69. // CHECK:STDOUT: .InstanceCall = %InstanceCall.decl
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core.import = import Core
  72. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [concrete = constants.%Simple.type] {} {}
  73. // CHECK:STDOUT: impl_decl @i32.as.Simple.impl [concrete] {} {
  74. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  75. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  76. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.type]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %Simple.impl_witness_table = impl_witness_table (@i32.as.Simple.impl.%i32.as.Simple.impl.G.decl.loc24_27.2), @i32.as.Simple.impl [concrete]
  79. // CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness %Simple.impl_witness_table [concrete = constants.%Simple.impl_witness]
  80. // CHECK:STDOUT: %InstanceCall.decl: %InstanceCall.type = fn_decl @InstanceCall [concrete = constants.%InstanceCall] {
  81. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = value_binding_pattern n [concrete]
  82. // CHECK:STDOUT: %n.param_patt: %pattern_type.7ce = value_param_pattern %n.patt, call_param0 [concrete]
  83. // CHECK:STDOUT: } {
  84. // CHECK:STDOUT: %n.param: %i32 = value_param call_param0
  85. // CHECK:STDOUT: %.loc27: type = splice_block %i32 [concrete = constants.%i32] {
  86. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  87. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %n: %i32 = value_binding n, %n.param
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: interface @Simple {
  94. // CHECK:STDOUT: %Self: %Simple.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  95. // CHECK:STDOUT: %Simple.G.decl: %Simple.G.type = fn_decl @Simple.G [concrete = constants.%Simple.G] {
  96. // CHECK:STDOUT: %self.patt: @Simple.G.%pattern_type (%pattern_type.52e) = value_binding_pattern self [concrete]
  97. // CHECK:STDOUT: %self.param_patt: @Simple.G.%pattern_type (%pattern_type.52e) = value_param_pattern %self.patt, call_param0 [concrete]
  98. // CHECK:STDOUT: } {
  99. // CHECK:STDOUT: %self.param: @Simple.G.%Self.binding.as_type (%Self.binding.as_type) = value_param call_param0
  100. // CHECK:STDOUT: %.loc16_14.1: type = splice_block %.loc16_14.2 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)] {
  101. // CHECK:STDOUT: %Self.ref: %Simple.type = name_ref Self, @Simple.%Self [symbolic = %Self (constants.%Self)]
  102. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self.ref [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  103. // CHECK:STDOUT: %.loc16_14.2: type = converted %Self.ref, %Self.as_type [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: %self: @Simple.G.%Self.binding.as_type (%Self.binding.as_type) = value_binding self, %self.param
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, %Simple.G.decl [concrete = constants.%assoc0]
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !members:
  110. // CHECK:STDOUT: .Self = %Self
  111. // CHECK:STDOUT: .G = %assoc0
  112. // CHECK:STDOUT: witness = (%Simple.G.decl)
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: !requires:
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: impl @i32.as.Simple.impl: %i32 as %Simple.ref {
  118. // CHECK:STDOUT: %i32.as.Simple.impl.G.decl.loc24_27.1: %i32.as.Simple.impl.G.type.4745bc.1 = fn_decl @i32.as.Simple.impl.G.loc24_27.1 [concrete = constants.%i32.as.Simple.impl.G.2bbe53.1] {
  119. // CHECK:STDOUT: %self.patt: <error> = value_binding_pattern self [concrete]
  120. // CHECK:STDOUT: %self.param_patt: <error> = value_param_pattern %self.patt, call_param0 [concrete]
  121. // CHECK:STDOUT: } {
  122. // CHECK:STDOUT: %self.param: <error> = value_param call_param0
  123. // CHECK:STDOUT: %Undeclared.ref: <error> = name_ref Undeclared, <error> [concrete = <error>]
  124. // CHECK:STDOUT: %self: <error> = value_binding self, %self.param
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %i32.as.Simple.impl.G.decl.loc24_27.2: %i32.as.Simple.impl.G.type.4745bc.2 = fn_decl @i32.as.Simple.impl.G.loc24_27.2 [concrete = constants.%i32.as.Simple.impl.G.2bbe53.2] {
  127. // CHECK:STDOUT: %self.patt: %pattern_type.7ce = value_binding_pattern self [concrete]
  128. // CHECK:STDOUT: %self.param_patt: %pattern_type.7ce = value_param_pattern %self.patt, call_param0 [concrete]
  129. // CHECK:STDOUT: } {
  130. // CHECK:STDOUT: %self.param: %i32 = value_param call_param0
  131. // CHECK:STDOUT: %self: %i32 = value_binding self, %self.param
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: !members:
  135. // CHECK:STDOUT: .Undeclared = <poisoned>
  136. // CHECK:STDOUT: .G = %i32.as.Simple.impl.G.decl.loc24_27.1
  137. // CHECK:STDOUT: witness = file.%Simple.impl_witness
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: generic fn @Simple.G(@Simple.%Self: %Simple.type) {
  141. // CHECK:STDOUT: %Self: %Simple.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self)]
  142. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  143. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic = %pattern_type (constants.%pattern_type.52e)]
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: fn(%self.param: @Simple.G.%Self.binding.as_type (%Self.binding.as_type));
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: fn @i32.as.Simple.impl.G.loc24_27.1(%self.param: <error>);
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn @i32.as.Simple.impl.G.loc24_27.2(%self.param: %i32) [thunk @i32.as.Simple.impl.%i32.as.Simple.impl.G.decl.loc24_27.1] {
  151. // CHECK:STDOUT: !entry:
  152. // CHECK:STDOUT: %G.ref: %i32.as.Simple.impl.G.type.4745bc.1 = name_ref G, @i32.as.Simple.impl.%i32.as.Simple.impl.G.decl.loc24_27.1 [concrete = constants.%i32.as.Simple.impl.G.2bbe53.1]
  153. // CHECK:STDOUT: %self.ref: %i32 = name_ref self, %self.param
  154. // CHECK:STDOUT: %i32.as.Simple.impl.G.bound: <bound method> = bound_method %self.ref, %G.ref
  155. // CHECK:STDOUT: %i32.as.Simple.impl.G.call: init %empty_tuple.type = call %i32.as.Simple.impl.G.bound(<error>)
  156. // CHECK:STDOUT: return
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: fn @InstanceCall(%n.param: %i32) {
  160. // CHECK:STDOUT: !entry:
  161. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  162. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.type]
  163. // CHECK:STDOUT: %G.ref.loc28_12: %Simple.assoc_type = name_ref G, @Simple.%assoc0 [concrete = constants.%assoc0]
  164. // CHECK:STDOUT: %impl.elem0: %.cb3 = impl_witness_access constants.%Simple.impl_witness, element0 [concrete = constants.%i32.as.Simple.impl.G.2bbe53.2]
  165. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %n.ref, %impl.elem0
  166. // CHECK:STDOUT: %G.ref.loc28_16: %i32.as.Simple.impl.G.type.4745bc.1 = name_ref G, @i32.as.Simple.impl.%i32.as.Simple.impl.G.decl.loc24_27.1 [concrete = constants.%i32.as.Simple.impl.G.2bbe53.1]
  167. // CHECK:STDOUT: %i32.as.Simple.impl.G.bound: <bound method> = bound_method %n.ref, %G.ref.loc28_16
  168. // CHECK:STDOUT: %i32.as.Simple.impl.G.call: init %empty_tuple.type = call %i32.as.Simple.impl.G.bound(<error>)
  169. // CHECK:STDOUT: return
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: specific @Simple.G(constants.%Self) {
  173. // CHECK:STDOUT: %Self => constants.%Self
  174. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  175. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.52e
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: specific @Simple.G(constants.%Simple.facet) {
  179. // CHECK:STDOUT: %Self => constants.%Simple.facet
  180. // CHECK:STDOUT: %Self.binding.as_type => constants.%i32
  181. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7ce
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT: