fail_impl_bad_interface.carbon 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. // --- fail_impl_as_false.carbon
  11. library "[[@TEST_NAME]]";
  12. // CHECK:STDERR: fail_impl_as_false.carbon:[[@LINE+7]]:13: error: cannot implicitly convert from `bool` to `type` [ImplicitAsConversionFailure]
  13. // CHECK:STDERR: impl i32 as false {}
  14. // CHECK:STDERR: ^~~~~
  15. // CHECK:STDERR: fail_impl_as_false.carbon:[[@LINE+4]]:13: note: type `bool` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  16. // CHECK:STDERR: impl i32 as false {}
  17. // CHECK:STDERR: ^~~~~
  18. // CHECK:STDERR:
  19. impl i32 as false {}
  20. // --- fail_impl_as_type.carbon
  21. library "[[@TEST_NAME]]";
  22. // CHECK:STDERR: fail_impl_as_type.carbon:[[@LINE+4]]:1: error: impl as non-facet type `type` [ImplAsNonFacetType]
  23. // CHECK:STDERR: impl bool as type {}
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. impl bool as type {}
  27. // --- fail_impl_as_type_where.carbon
  28. library "[[@TEST_NAME]]";
  29. // Note: This code is not expected to pass checking, even once the TODO is
  30. // addressed.
  31. // CHECK:STDERR: fail_impl_as_type_where.carbon:[[@LINE+4]]:1: error: semantics TODO: `impl as not 1 interface` [SemanticsTodo]
  32. // CHECK:STDERR: impl f64 as type where .Self impls type {}
  33. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. // CHECK:STDERR:
  35. impl f64 as type where .Self impls type {}
  36. // CHECK:STDOUT: --- fail_impl_as_false.carbon
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: constants {
  39. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  40. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  41. // CHECK:STDOUT: %false: bool = bool_literal false [template]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: imports {
  45. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  46. // CHECK:STDOUT: .Int = %import_ref.485
  47. // CHECK:STDOUT: .ImplicitAs = %import_ref.d44
  48. // CHECK:STDOUT: import Core//prelude
  49. // CHECK:STDOUT: import Core//prelude/...
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core.import = import Core
  58. // CHECK:STDOUT: %.loc11: type = converted @impl.%false, <error> [template = <error>]
  59. // CHECK:STDOUT: impl_decl @impl [template] {} {
  60. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  61. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  62. // CHECK:STDOUT: %false: bool = bool_literal false [template = constants.%false]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: impl @impl: %i32 as <error> {
  67. // CHECK:STDOUT: !members:
  68. // CHECK:STDOUT: witness = <error>
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: --- fail_impl_as_type.carbon
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: constants {
  74. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  75. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: imports {
  79. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  80. // CHECK:STDOUT: .Bool = %import_ref
  81. // CHECK:STDOUT: import Core//prelude
  82. // CHECK:STDOUT: import Core//prelude/...
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: file {
  87. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  88. // CHECK:STDOUT: .Core = imports.%Core
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %Core.import = import Core
  91. // CHECK:STDOUT: impl_decl @impl [template] {} {
  92. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  93. // CHECK:STDOUT: %.loc8_6.1: type = value_of_initializer %bool.make_type [template = bool]
  94. // CHECK:STDOUT: %.loc8_6.2: type = converted %bool.make_type, %.loc8_6.1 [template = bool]
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: impl @impl: %.loc8_6.2 as type {
  99. // CHECK:STDOUT: !members:
  100. // CHECK:STDOUT: witness = <error>
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: --- fail_impl_as_type_where.carbon
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: constants {
  106. // CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [template]
  107. // CHECK:STDOUT: %Float.type: type = fn_type @Float [template]
  108. // CHECK:STDOUT: %Float: %Float.type = struct_value () [template]
  109. // CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self [symbolic]
  110. // CHECK:STDOUT: %type_where: type = facet_type <type where TODO> [template]
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: imports {
  114. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  115. // CHECK:STDOUT: .Float = %import_ref
  116. // CHECK:STDOUT: import Core//prelude
  117. // CHECK:STDOUT: import Core//prelude/...
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: file {
  122. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  123. // CHECK:STDOUT: .Core = imports.%Core
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: %Core.import = import Core
  126. // CHECK:STDOUT: impl_decl @impl [template] {} {
  127. // CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [template = constants.%int_64]
  128. // CHECK:STDOUT: %float.make_type: init type = call constants.%Float(%int_64) [template = f64]
  129. // CHECK:STDOUT: %.loc11_6.1: type = value_of_initializer %float.make_type [template = f64]
  130. // CHECK:STDOUT: %.loc11_6.2: type = converted %float.make_type, %.loc11_6.1 [template = f64]
  131. // CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self [symbolic = constants.%.Self]
  132. // CHECK:STDOUT: %.Self.ref: type = name_ref .Self, %.Self [symbolic = constants.%.Self]
  133. // CHECK:STDOUT: %.loc11_18: type = where_expr %.Self [template = constants.%type_where] {
  134. // CHECK:STDOUT: requirement_impls %.Self.ref, type
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: impl @impl: %.loc11_6.2 as %.loc11_18 {
  140. // CHECK:STDOUT: !members:
  141. // CHECK:STDOUT: witness = <error>
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: