fail_impl_bad_interface.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_impl_bad_interface.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_impl_bad_interface.carbon
  10. // CHECK:STDERR: fail_impl_bad_interface.carbon:[[@LINE+10]]:1: error: semantics TODO: `impl as non-interface`
  11. // CHECK:STDERR: impl i32 as false {}
  12. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
  13. // CHECK:STDERR:
  14. // CHECK:STDERR: fail_impl_bad_interface.carbon:[[@LINE+6]]:13: error: cannot implicitly convert from `bool` to `type`
  15. // CHECK:STDERR: impl i32 as false {}
  16. // CHECK:STDERR: ^~~~~
  17. // CHECK:STDERR: fail_impl_bad_interface.carbon:[[@LINE+3]]:13: note: type `bool` does not implement interface `ImplicitAs`
  18. // CHECK:STDERR: impl i32 as false {}
  19. // CHECK:STDERR: ^~~~~
  20. impl i32 as false {}
  21. // CHECK:STDOUT: --- fail_impl_bad_interface.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  25. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  26. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  27. // CHECK:STDOUT: %.2: bool = bool_literal false [template]
  28. // CHECK:STDOUT: %ImplicitAs.type: type = generic_interface_type @ImplicitAs [template]
  29. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type = struct_value () [template]
  30. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic]
  31. // CHECK:STDOUT: %.3: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  32. // CHECK:STDOUT: %Self.1: @ImplicitAs.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
  33. // CHECK:STDOUT: %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
  34. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  35. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  36. // CHECK:STDOUT: %.4: type = assoc_entity_type %.3, %Convert.type.1 [symbolic]
  37. // CHECK:STDOUT: %.5: %.4 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  38. // CHECK:STDOUT: %.6: type = interface_type @ImplicitAs, @ImplicitAs(type) [template]
  39. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(type) [template]
  40. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  41. // CHECK:STDOUT: %.7: type = assoc_entity_type %.6, %Convert.type.2 [template]
  42. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.6 [template]
  43. // CHECK:STDOUT: %.9: %.4 = assoc_entity element0, imports.%import_ref.7 [symbolic]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  48. // CHECK:STDOUT: .Int32 = %import_ref.1
  49. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/operators
  52. // CHECK:STDOUT: import Core//prelude/types
  53. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  54. // CHECK:STDOUT: import Core//prelude/operators/as
  55. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  56. // CHECK:STDOUT: import Core//prelude/operators/comparison
  57. // CHECK:STDOUT: import Core//prelude/types/bool
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  60. // CHECK:STDOUT: %import_ref.2: %ImplicitAs.type = import_ref Core//prelude/operators/as, inst+37, loaded [template = constants.%ImplicitAs]
  61. // CHECK:STDOUT: %import_ref.3 = import_ref Core//prelude/operators/as, inst+42, unloaded
  62. // CHECK:STDOUT: %import_ref.4: @ImplicitAs.%.2 (%.4) = import_ref Core//prelude/operators/as, inst+59, loaded [symbolic = @ImplicitAs.%.3 (constants.%.9)]
  63. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/as, inst+52, unloaded
  64. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+52, unloaded
  65. // CHECK:STDOUT: %import_ref.7 = import_ref Core//prelude/operators/as, inst+52, unloaded
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: file {
  69. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  70. // CHECK:STDOUT: .Core = imports.%Core
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core.import = import Core
  73. // CHECK:STDOUT: %.loc21_13.1: type = interface_type @ImplicitAs, @ImplicitAs(type) [template = constants.%.6]
  74. // CHECK:STDOUT: %.loc21_13.2: %.7 = specific_constant imports.%import_ref.4, @ImplicitAs(type) [template = constants.%.8]
  75. // CHECK:STDOUT: %Convert.ref: %.7 = name_ref Convert, %.loc21_13.2 [template = constants.%.8]
  76. // CHECK:STDOUT: %.loc21_13.3: type = converted %.loc21_13.4, <error> [template = <error>]
  77. // CHECK:STDOUT: impl_decl @impl {
  78. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  79. // CHECK:STDOUT: %.loc21_6.1: type = value_of_initializer %int.make_type_32 [template = i32]
  80. // CHECK:STDOUT: %.loc21_6.2: type = converted %int.make_type_32, %.loc21_6.1 [template = i32]
  81. // CHECK:STDOUT: %.loc21_13.4: bool = bool_literal false [template = constants.%.2]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  86. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: !definition:
  89. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.3)]
  90. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  91. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  92. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  93. // CHECK:STDOUT: %.2: type = assoc_entity_type @ImplicitAs.%.1 (%.3), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.2 (constants.%.4)]
  94. // CHECK:STDOUT: %.3: @ImplicitAs.%.2 (%.4) = assoc_entity element0, imports.%import_ref.6 [symbolic = %.3 (constants.%.5)]
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: interface {
  97. // CHECK:STDOUT: !members:
  98. // CHECK:STDOUT: .Self = imports.%import_ref.3
  99. // CHECK:STDOUT: .Convert = imports.%import_ref.4
  100. // CHECK:STDOUT: witness = (imports.%import_ref.5)
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: impl @impl: i32 as <error> {
  105. // CHECK:STDOUT: !members:
  106. // CHECK:STDOUT: witness = <error>
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%.1 (%.3)) {
  112. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  113. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.3)]
  114. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: fn[%self: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  120. // CHECK:STDOUT: %Dest => constants.%Dest
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  124. // CHECK:STDOUT: %Dest => constants.%Dest
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  128. // CHECK:STDOUT: %Dest => constants.%Dest
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  132. // CHECK:STDOUT: %Dest => constants.%Dest
  133. // CHECK:STDOUT: %.1 => constants.%.3
  134. // CHECK:STDOUT: %Self => constants.%Self.1
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: specific @ImplicitAs(type) {
  138. // CHECK:STDOUT: %Dest => type
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: !definition:
  141. // CHECK:STDOUT: %.1 => constants.%.6
  142. // CHECK:STDOUT: %Self => constants.%Self.2
  143. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  144. // CHECK:STDOUT: %Convert => constants.%Convert.2
  145. // CHECK:STDOUT: %.2 => constants.%.7
  146. // CHECK:STDOUT: %.3 => constants.%.8
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: