fail_call_invalid.carbon 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/impl/fail_call_invalid.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_call_invalid.carbon
  10. interface Simple {
  11. fn G[self: Self]();
  12. }
  13. impl i32 as Simple {
  14. // CHECK:STDERR: fail_call_invalid.carbon:[[@LINE+3]]:14: error: name `Undeclared` not found
  15. // CHECK:STDERR: fn G[self: Undeclared]();
  16. // CHECK:STDERR: ^~~~~~~~~~
  17. fn G[self: Undeclared]();
  18. }
  19. fn InstanceCall(n: i32) {
  20. n.(Simple.G)();
  21. }
  22. // CHECK:STDOUT: --- fail_call_invalid.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %.1: type = interface_type @Simple [template]
  26. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self, 0 [symbolic]
  27. // CHECK:STDOUT: %G.type.1: type = fn_type @G.1 [template]
  28. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  29. // CHECK:STDOUT: %G.1: %G.type.1 = struct_value () [template]
  30. // CHECK:STDOUT: %.3: type = assoc_entity_type %.1, %G.type.1 [template]
  31. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @Simple.%G.decl [template]
  32. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  33. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  34. // CHECK:STDOUT: %G.type.2: type = fn_type @G.2 [template]
  35. // CHECK:STDOUT: %G.2: %G.type.2 = struct_value () [template]
  36. // CHECK:STDOUT: %InstanceCall.type: type = fn_type @InstanceCall [template]
  37. // CHECK:STDOUT: %InstanceCall: %InstanceCall.type = struct_value () [template]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: imports {
  41. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  42. // CHECK:STDOUT: .Int32 = %import_ref
  43. // CHECK:STDOUT: import Core//prelude
  44. // CHECK:STDOUT: import Core//prelude/operators
  45. // CHECK:STDOUT: import Core//prelude/types
  46. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  47. // CHECK:STDOUT: import Core//prelude/operators/as
  48. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  49. // CHECK:STDOUT: import Core//prelude/operators/comparison
  50. // CHECK:STDOUT: import Core//prelude/types/bool
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .Simple = %Simple.decl
  59. // CHECK:STDOUT: .InstanceCall = %InstanceCall.decl
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.import = import Core
  62. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [template = constants.%.1] {} {}
  63. // CHECK:STDOUT: impl_decl @impl [template] {} {
  64. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  65. // CHECK:STDOUT: %.loc15_6.1: type = value_of_initializer %int.make_type_32 [template = i32]
  66. // CHECK:STDOUT: %.loc15_6.2: type = converted %int.make_type_32, %.loc15_6.1 [template = i32]
  67. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %InstanceCall.decl: %InstanceCall.type = fn_decl @InstanceCall [template = constants.%InstanceCall] {
  70. // CHECK:STDOUT: %n.patt: i32 = binding_pattern n
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  73. // CHECK:STDOUT: %.loc22_20.1: type = value_of_initializer %int.make_type_32 [template = i32]
  74. // CHECK:STDOUT: %.loc22_20.2: type = converted %int.make_type_32, %.loc22_20.1 [template = i32]
  75. // CHECK:STDOUT: %n.param: i32 = param n, runtime_param0
  76. // CHECK:STDOUT: %n: i32 = bind_name n, %n.param
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: interface @Simple {
  81. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  82. // CHECK:STDOUT: %G.decl: %G.type.1 = fn_decl @G.1 [template = constants.%G.1] {
  83. // CHECK:STDOUT: %self.patt: @G.1.%Self (%Self) = binding_pattern self
  84. // CHECK:STDOUT: } {
  85. // CHECK:STDOUT: %Self.ref: %.1 = name_ref Self, @Simple.%Self [symbolic = %Self (constants.%Self)]
  86. // CHECK:STDOUT: %.loc12_14.1: type = facet_type_access %Self.ref [symbolic = %Self (constants.%Self)]
  87. // CHECK:STDOUT: %.loc12_14.2: type = converted %Self.ref, %.loc12_14.1 [symbolic = %Self (constants.%Self)]
  88. // CHECK:STDOUT: %self.param: @G.1.%Self (%Self) = param self, runtime_param0
  89. // CHECK:STDOUT: %self: @G.1.%Self (%Self) = bind_name self, %self.param
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %.loc12: %.3 = assoc_entity element0, %G.decl [template = constants.%.4]
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: !members:
  94. // CHECK:STDOUT: .Self = %Self
  95. // CHECK:STDOUT: .G = %.loc12
  96. // CHECK:STDOUT: witness = (%G.decl)
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: impl @impl: %.loc15_6.2 as %Simple.ref {
  100. // CHECK:STDOUT: %G.decl: %G.type.2 = fn_decl @G.2 [template = constants.%G.2] {
  101. // CHECK:STDOUT: %self.patt: <error> = binding_pattern self
  102. // CHECK:STDOUT: } {
  103. // CHECK:STDOUT: %Undeclared.ref: <error> = name_ref Undeclared, <error> [template = <error>]
  104. // CHECK:STDOUT: %self.param: <error> = param self, runtime_param0
  105. // CHECK:STDOUT: %self: <error> = bind_name self, %self.param
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: %.loc15_20: <witness> = interface_witness (<error>) [template = <error>]
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !members:
  110. // CHECK:STDOUT: .G = %G.decl
  111. // CHECK:STDOUT: witness = %.loc15_20
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: generic fn @G.1(@Simple.%Self: %.1) {
  115. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: fn[%self: @G.1.%Self (%Self)]();
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: fn @G.2[%self: <error>]();
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @InstanceCall(%n: i32) {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  127. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  128. // CHECK:STDOUT: %G.ref: %.3 = name_ref G, @Simple.%.loc12 [template = constants.%.4]
  129. // CHECK:STDOUT: %.loc23_4.1: %G.type.1 = interface_witness_access <error>, element0 [template = <error>]
  130. // CHECK:STDOUT: %.loc23_4.2: <bound method> = bound_method %n.ref, %.loc23_4.1
  131. // CHECK:STDOUT: return
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: specific @G.1(constants.%Self) {
  135. // CHECK:STDOUT: %Self => constants.%Self
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: specific @G.1(i32) {
  139. // CHECK:STDOUT: %Self => i32
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: