fail_extend_impl_scope.carbon 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/no_prelude/fail_extend_impl_scope.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/no_prelude/fail_extend_impl_scope.carbon
  10. // --- fail_extend_impl_file_scope.carbon
  11. library "[[@TEST_NAME]]";
  12. interface I {}
  13. // CHECK:STDERR: fail_extend_impl_file_scope.carbon:[[@LINE+4]]:1: error: `extend impl` can only be used in a class [ExtendImplOutsideClass]
  14. // CHECK:STDERR: extend impl () as I {}
  15. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  16. // CHECK:STDERR:
  17. extend impl () as I {}
  18. // --- fail_extend_impl_function_scope.carbon
  19. library "[[@TEST_NAME]]";
  20. interface J {}
  21. fn F() {
  22. // CHECK:STDERR: fail_extend_impl_function_scope.carbon:[[@LINE+4]]:3: error: `extend impl` can only be used in a class [ExtendImplOutsideClass]
  23. // CHECK:STDERR: extend impl {} as J {}
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. extend impl {} as J {}
  27. }
  28. // CHECK:STDOUT: --- fail_extend_impl_file_scope.carbon
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: constants {
  31. // CHECK:STDOUT: %I.type: type = facet_type <@I> [template]
  32. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  33. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  34. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness () [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .I = %I.decl
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%I.type] {} {}
  42. // CHECK:STDOUT: impl_decl @impl [template] {} {
  43. // CHECK:STDOUT: %.loc9_14.1: %empty_tuple.type = tuple_literal ()
  44. // CHECK:STDOUT: %.loc9_14.2: type = converted %.loc9_14.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  45. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%I.type]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness () [template = constants.%impl_witness]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: interface @I {
  51. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: !members:
  54. // CHECK:STDOUT: .Self = %Self
  55. // CHECK:STDOUT: witness = ()
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: impl @impl: %.loc9_14.2 as %I.ref {
  59. // CHECK:STDOUT: !members:
  60. // CHECK:STDOUT: witness = file.%impl_witness
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: --- fail_extend_impl_function_scope.carbon
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: constants {
  66. // CHECK:STDOUT: %J.type: type = facet_type <@J> [template]
  67. // CHECK:STDOUT: %Self: %J.type = bind_symbolic_name Self, 0 [symbolic]
  68. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  69. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  70. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  71. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness () [template]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  76. // CHECK:STDOUT: .J = %J.decl
  77. // CHECK:STDOUT: .F = %F.decl
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %J.decl: type = interface_decl @J [template = constants.%J.type] {} {}
  80. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: interface @J {
  84. // CHECK:STDOUT: %Self: %J.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = %Self
  88. // CHECK:STDOUT: witness = ()
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: impl @impl: %.loc10_16.2 as %J.ref {
  92. // CHECK:STDOUT: !members:
  93. // CHECK:STDOUT: witness = @F.%impl_witness
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @F() {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: impl_decl @impl [template] {} {
  99. // CHECK:STDOUT: %.loc10_16.1: %empty_struct_type = struct_literal ()
  100. // CHECK:STDOUT: %.loc10_16.2: type = converted %.loc10_16.1, constants.%empty_struct_type [template = constants.%empty_struct_type]
  101. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [template = constants.%J.type]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness () [template = constants.%impl_witness]
  104. // CHECK:STDOUT: return
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: