fail_impl_as_scope.carbon 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. interface Simple {
  11. fn F();
  12. }
  13. // CHECK:STDERR: fail_impl_as_scope.carbon:[[@LINE+3]]:6: error: `impl as` can only be used in a class
  14. // CHECK:STDERR: impl as Simple {
  15. // CHECK:STDERR: ^~
  16. impl as Simple {
  17. fn F() {}
  18. }
  19. // CHECK:STDOUT: --- fail_impl_as_scope.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %.1: type = interface_type @Simple [template]
  23. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self, 0 [symbolic]
  24. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  25. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  26. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  27. // CHECK:STDOUT: %.3: type = assoc_entity_type %.1, %F.type.1 [template]
  28. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @Simple.%F.decl [template]
  29. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  30. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  31. // CHECK:STDOUT: %.5: <witness> = interface_witness (%F.2) [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/operators
  38. // CHECK:STDOUT: import Core//prelude/types
  39. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  40. // CHECK:STDOUT: import Core//prelude/operators/as
  41. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  42. // CHECK:STDOUT: import Core//prelude/operators/comparison
  43. // CHECK:STDOUT: import Core//prelude/types/bool
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: file {
  48. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  49. // CHECK:STDOUT: .Core = imports.%Core
  50. // CHECK:STDOUT: .Simple = %Simple.decl
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %Core.import = import Core
  53. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [template = constants.%.1] {} {}
  54. // CHECK:STDOUT: impl_decl @impl [template] {} {
  55. // CHECK:STDOUT: %Self.ref: type = name_ref Self, <error> [template = <error>]
  56. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: interface @Simple {
  61. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  62. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  63. // CHECK:STDOUT: %.loc12: %.3 = assoc_entity element0, %F.decl [template = constants.%.4]
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: !members:
  66. // CHECK:STDOUT: .Self = %Self
  67. // CHECK:STDOUT: .F = %.loc12
  68. // CHECK:STDOUT: witness = (%F.decl)
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: impl @impl: %Self.ref as %Simple.ref {
  72. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  73. // CHECK:STDOUT: %.loc18: <witness> = interface_witness (%F.decl) [template = constants.%.5]
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !members:
  76. // CHECK:STDOUT: .F = %F.decl
  77. // CHECK:STDOUT: witness = %.loc18
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: generic fn @F.1(@Simple.%Self: %.1) {
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn();
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @F.2() {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: return
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: specific @F.1(<error>) {}
  93. // CHECK:STDOUT: