fail_redefinition.carbon 6.2 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/class/fail_redefinition.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_redefinition.carbon
  10. class Class {
  11. fn F();
  12. fn H();
  13. fn I() {}
  14. }
  15. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE+7]]:1: error: redefinition of `class Class` [RedeclRedef]
  16. // CHECK:STDERR: class Class {
  17. // CHECK:STDERR: ^~~~~~~~~~~~~
  18. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE-9]]:1: note: previously defined here [RedeclPrevDef]
  19. // CHECK:STDERR: class Class {
  20. // CHECK:STDERR: ^~~~~~~~~~~~~
  21. // CHECK:STDERR:
  22. class Class {
  23. fn G();
  24. fn H();
  25. fn I() {}
  26. }
  27. fn Class.F() {}
  28. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE+4]]:10: error: out-of-line declaration requires a declaration in scoped entity [QualifiedDeclOutsideScopeEntity]
  29. // CHECK:STDERR: fn Class.G() {}
  30. // CHECK:STDERR: ^
  31. // CHECK:STDERR:
  32. fn Class.G() {}
  33. fn Class.H() {}
  34. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE+7]]:1: error: redefinition of `fn I` [RedeclRedef]
  35. // CHECK:STDERR: fn Class.I() {}
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~
  37. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE-26]]:3: note: previously defined here [RedeclPrevDef]
  38. // CHECK:STDERR: fn I() {}
  39. // CHECK:STDERR: ^~~~~~~~
  40. // CHECK:STDERR:
  41. fn Class.I() {}
  42. // CHECK:STDOUT: --- fail_redefinition.carbon
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: constants {
  45. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  46. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  47. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  48. // CHECK:STDOUT: %H.type.91d: type = fn_type @H.1 [template]
  49. // CHECK:STDOUT: %H.d38: %H.type.91d = struct_value () [template]
  50. // CHECK:STDOUT: %I.type.2b6: type = fn_type @I.1 [template]
  51. // CHECK:STDOUT: %I.c9a: %I.type.2b6 = struct_value () [template]
  52. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  53. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  54. // CHECK:STDOUT: %.a95: type = class_type @.2 [template]
  55. // CHECK:STDOUT: %G.type.bf6: type = fn_type @G.1 [template]
  56. // CHECK:STDOUT: %G.e39: %G.type.bf6 = struct_value () [template]
  57. // CHECK:STDOUT: %H.type.e2f: type = fn_type @H.2 [template]
  58. // CHECK:STDOUT: %H.382: %H.type.e2f = struct_value () [template]
  59. // CHECK:STDOUT: %I.type.b27: type = fn_type @I.2 [template]
  60. // CHECK:STDOUT: %I.a7f: %I.type.b27 = struct_value () [template]
  61. // CHECK:STDOUT: %G.type.621: type = fn_type @G.2 [template]
  62. // CHECK:STDOUT: %G.f0c: %G.type.621 = struct_value () [template]
  63. // CHECK:STDOUT: %.type: type = fn_type @.1 [template]
  64. // CHECK:STDOUT: %.d22: %.type = struct_value () [template]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: imports {
  68. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  69. // CHECK:STDOUT: import Core//prelude
  70. // CHECK:STDOUT: import Core//prelude/...
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  76. // CHECK:STDOUT: .Core = imports.%Core
  77. // CHECK:STDOUT: .Class = %Class.decl
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %Core.import = import Core
  80. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  81. // CHECK:STDOUT: %.decl.loc24: type = class_decl @.2 [template = constants.%.a95] {} {}
  82. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  83. // CHECK:STDOUT: %G.decl: %G.type.621 = fn_decl @G.2 [template = constants.%G.f0c] {} {}
  84. // CHECK:STDOUT: %H.decl: %H.type.91d = fn_decl @H.1 [template = constants.%H.d38] {} {}
  85. // CHECK:STDOUT: %.decl.loc44: %.type = fn_decl @.1 [template = constants.%.d22] {} {}
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: class @Class {
  89. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  90. // CHECK:STDOUT: %H.decl: %H.type.91d = fn_decl @H.1 [template = constants.%H.d38] {} {}
  91. // CHECK:STDOUT: %I.decl: %I.type.2b6 = fn_decl @I.1 [template = constants.%I.c9a] {} {}
  92. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  93. // CHECK:STDOUT: complete_type_witness = %complete_type
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !members:
  96. // CHECK:STDOUT: .Self = constants.%Class
  97. // CHECK:STDOUT: .F = %F.decl
  98. // CHECK:STDOUT: .H = %H.decl
  99. // CHECK:STDOUT: .I = %I.decl
  100. // CHECK:STDOUT: .G = file.%G.decl
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: class @.2 {
  104. // CHECK:STDOUT: %G.decl: %G.type.bf6 = fn_decl @G.1 [template = constants.%G.e39] {} {}
  105. // CHECK:STDOUT: %H.decl: %H.type.e2f = fn_decl @H.2 [template = constants.%H.382] {} {}
  106. // CHECK:STDOUT: %I.decl: %I.type.b27 = fn_decl @I.2 [template = constants.%I.a7f] {} {}
  107. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  108. // CHECK:STDOUT: complete_type_witness = %complete_type
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: !members:
  111. // CHECK:STDOUT: .Self = constants.%.a95
  112. // CHECK:STDOUT: .G = %G.decl
  113. // CHECK:STDOUT: .H = %H.decl
  114. // CHECK:STDOUT: .I = %I.decl
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: fn @F() {
  118. // CHECK:STDOUT: !entry:
  119. // CHECK:STDOUT: return
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: fn @H.1() {
  123. // CHECK:STDOUT: !entry:
  124. // CHECK:STDOUT: return
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: fn @I.1() {
  128. // CHECK:STDOUT: !entry:
  129. // CHECK:STDOUT: return
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: fn @G.1();
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: fn @H.2();
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: fn @I.2() {
  137. // CHECK:STDOUT: !entry:
  138. // CHECK:STDOUT: return
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: fn @G.2() {
  142. // CHECK:STDOUT: !entry:
  143. // CHECK:STDOUT: return
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: fn @.1() {
  147. // CHECK:STDOUT: !entry:
  148. // CHECK:STDOUT: return
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: