fail_impl_as_scope.carbon 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_as_scope.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_as_scope.carbon
  10. // --- fail_global.carbon
  11. library "[[@TEST_NAME]]";
  12. interface Simple {
  13. fn F();
  14. }
  15. // CHECK:STDERR: fail_global.carbon:[[@LINE+4]]:6: error: `impl as` can only be used in a class [ImplAsOutsideClass]
  16. // CHECK:STDERR: impl as Simple {
  17. // CHECK:STDERR: ^~
  18. // CHECK:STDERR:
  19. impl as Simple {
  20. fn F() {}
  21. }
  22. // --- fail_function.carbon
  23. library "[[@TEST_NAME]]";
  24. interface Simple {
  25. fn F();
  26. }
  27. fn Function() {
  28. // CHECK:STDERR: fail_function.carbon:[[@LINE+4]]:8: error: `impl as` can only be used in a class [ImplAsOutsideClass]
  29. // CHECK:STDERR: impl as Simple {
  30. // CHECK:STDERR: ^~
  31. // CHECK:STDERR:
  32. impl as Simple {
  33. fn F() {}
  34. }
  35. }
  36. // CHECK:STDOUT: --- fail_global.carbon
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: constants {
  39. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple> [template]
  40. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic]
  41. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  42. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  43. // CHECK:STDOUT: %Simple.assoc_type: type = assoc_entity_type %Simple.type [template]
  44. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, @Simple.%F.decl [template]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: file {}
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: interface @Simple {
  50. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  51. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  52. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, %F.decl [template = constants.%assoc0]
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: !members:
  55. // CHECK:STDOUT: .Self = %Self
  56. // CHECK:STDOUT: .F = %assoc0
  57. // CHECK:STDOUT: witness = (%F.decl)
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: generic fn @F(@Simple.%Self: %Simple.type) {
  61. // CHECK:STDOUT: fn();
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: specific @F(constants.%Self) {}
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: --- fail_function.carbon
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: constants {
  69. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple> [template]
  70. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic]
  71. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  72. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  73. // CHECK:STDOUT: %Simple.assoc_type: type = assoc_entity_type %Simple.type [template]
  74. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, @Simple.%F.decl [template]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: file {}
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: interface @Simple {
  80. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  81. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  82. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, %F.decl [template = constants.%assoc0]
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !members:
  85. // CHECK:STDOUT: .Self = %Self
  86. // CHECK:STDOUT: .F = %assoc0
  87. // CHECK:STDOUT: witness = (%F.decl)
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: generic fn @F(@Simple.%Self: %Simple.type) {
  91. // CHECK:STDOUT: fn();
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @Function();
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: specific @F(constants.%Self) {}
  97. // CHECK:STDOUT: