fail_base_misplaced.carbon 4.4 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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_base_misplaced.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_base_misplaced.carbon
  13. base class B {}
  14. // CHECK:STDERR: fail_base_misplaced.carbon:[[@LINE+4]]:1: error: `base` declaration outside class [ClassSpecificDeclOutsideClass]
  15. // CHECK:STDERR: extend base: B;
  16. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  17. // CHECK:STDERR:
  18. extend base: B;
  19. fn F() {
  20. // CHECK:STDERR: fail_base_misplaced.carbon:[[@LINE+4]]:3: error: `base` declaration outside class [ClassSpecificDeclOutsideClass]
  21. // CHECK:STDERR: extend base: B;
  22. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  23. // CHECK:STDERR:
  24. extend base: B;
  25. }
  26. class C {
  27. fn F() {
  28. // CHECK:STDERR: fail_base_misplaced.carbon:[[@LINE+4]]:5: error: `base` declaration outside class [ClassSpecificDeclOutsideClass]
  29. // CHECK:STDERR: extend base: B;
  30. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  31. // CHECK:STDERR:
  32. extend base: B;
  33. }
  34. }
  35. // CHECK:STDOUT: --- fail_base_misplaced.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  39. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  40. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  41. // CHECK:STDOUT: %F.type.b25: type = fn_type @F.1 [concrete]
  42. // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [concrete]
  43. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  44. // CHECK:STDOUT: %F.type.c29: type = fn_type @F.2 [concrete]
  45. // CHECK:STDOUT: %F.437: %F.type.c29 = struct_value () [concrete]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: imports {
  49. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/...
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .B = %B.decl
  59. // CHECK:STDOUT: .F = %F.decl
  60. // CHECK:STDOUT: .C = %C.decl
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Core.import = import Core
  63. // CHECK:STDOUT: %B.decl: type = class_decl @B [concrete = constants.%B] {} {}
  64. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [concrete = constants.%B]
  65. // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.1 [concrete = constants.%F.c41] {} {}
  66. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: class @B {
  70. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  71. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  72. // CHECK:STDOUT: complete_type_witness = %complete_type
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = constants.%B
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: class @C {
  79. // CHECK:STDOUT: %F.decl: %F.type.c29 = fn_decl @F.2 [concrete = constants.%F.437] {} {}
  80. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  81. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  82. // CHECK:STDOUT: complete_type_witness = %complete_type
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !members:
  85. // CHECK:STDOUT: .Self = constants.%C
  86. // CHECK:STDOUT: .F = %F.decl
  87. // CHECK:STDOUT: .B = <poisoned>
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @F.1() {
  91. // CHECK:STDOUT: !entry:
  92. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  93. // CHECK:STDOUT: return
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @F.2() {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  99. // CHECK:STDOUT: return
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: