fail_redefinition.carbon 6.1 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`
  16. // CHECK:STDERR: class Class {
  17. // CHECK:STDERR: ^~~~~~~~~~~~~
  18. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE-9]]:1: note: previously defined here
  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
  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+6]]:1: error: redefinition of `fn I`
  35. // CHECK:STDERR: fn Class.I() {}
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~
  37. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE-26]]:3: note: previously defined here
  38. // CHECK:STDERR: fn I() {}
  39. // CHECK:STDERR: ^~~~~~~~
  40. fn Class.I() {}
  41. // CHECK:STDOUT: --- fail_redefinition.carbon
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: constants {
  44. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  45. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  46. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  47. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  48. // CHECK:STDOUT: %H.type.1: type = fn_type @H.1 [template]
  49. // CHECK:STDOUT: %H.1: %H.type.1 = struct_value () [template]
  50. // CHECK:STDOUT: %I.type.1: type = fn_type @I.1 [template]
  51. // CHECK:STDOUT: %I.1: %I.type.1 = struct_value () [template]
  52. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  53. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  54. // CHECK:STDOUT: %.4: type = class_type @.1 [template]
  55. // CHECK:STDOUT: %G.type.1: type = fn_type @G.1 [template]
  56. // CHECK:STDOUT: %G.1: %G.type.1 = struct_value () [template]
  57. // CHECK:STDOUT: %H.type.2: type = fn_type @H.2 [template]
  58. // CHECK:STDOUT: %H.2: %H.type.2 = struct_value () [template]
  59. // CHECK:STDOUT: %I.type.2: type = fn_type @I.2 [template]
  60. // CHECK:STDOUT: %I.2: %I.type.2 = struct_value () [template]
  61. // CHECK:STDOUT: %G.type.2: type = fn_type @G.2 [template]
  62. // CHECK:STDOUT: %G.2: %G.type.2 = struct_value () [template]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: imports {
  66. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  67. // CHECK:STDOUT: import Core//prelude
  68. // CHECK:STDOUT: import Core//prelude/operators
  69. // CHECK:STDOUT: import Core//prelude/types
  70. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  71. // CHECK:STDOUT: import Core//prelude/operators/as
  72. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  73. // CHECK:STDOUT: import Core//prelude/operators/comparison
  74. // CHECK:STDOUT: import Core//prelude/types/bool
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: file {
  79. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  80. // CHECK:STDOUT: .Core = imports.%Core
  81. // CHECK:STDOUT: .Class = %Class.decl
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %Core.import = import Core
  84. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  85. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.4] {} {}
  86. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  87. // CHECK:STDOUT: %G.decl: %G.type.2 = fn_decl @G.2 [template = constants.%G.2] {} {}
  88. // CHECK:STDOUT: %H.decl: %H.type.1 = fn_decl @H.1 [template = constants.%H.1] {} {}
  89. // CHECK:STDOUT: %I.decl: %I.type.1 = fn_decl @I.1 [template = constants.%I.1] {} {}
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: class @Class {
  93. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  94. // CHECK:STDOUT: %H.decl: %H.type.1 = fn_decl @H.1 [template = constants.%H.1] {} {}
  95. // CHECK:STDOUT: %I.decl: %I.type.1 = fn_decl @I.1 [template = constants.%I.1] {} {}
  96. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.2 [template = constants.%.3]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .Self = constants.%Class
  100. // CHECK:STDOUT: .F = %F.decl
  101. // CHECK:STDOUT: .H = %H.decl
  102. // CHECK:STDOUT: .I = %I.decl
  103. // CHECK:STDOUT: .G = file.%G.decl
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: class @.1 {
  107. // CHECK:STDOUT: %G.decl: %G.type.1 = fn_decl @G.1 [template = constants.%G.1] {} {}
  108. // CHECK:STDOUT: %H.decl: %H.type.2 = fn_decl @H.2 [template = constants.%H.2] {} {}
  109. // CHECK:STDOUT: %I.decl: %I.type.2 = fn_decl @I.2 [template = constants.%I.2] {} {}
  110. // CHECK:STDOUT: %.loc28: <witness> = complete_type_witness %.2 [template = constants.%.3]
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: !members:
  113. // CHECK:STDOUT: .Self = constants.%.4
  114. // CHECK:STDOUT: .G = %G.decl
  115. // CHECK:STDOUT: .H = %H.decl
  116. // CHECK:STDOUT: .I = %I.decl
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn @F() {
  120. // CHECK:STDOUT: !entry:
  121. // CHECK:STDOUT: return
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @H.1() {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: return
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: fn @I.1() {
  130. // CHECK:STDOUT: !entry:
  131. // CHECK:STDOUT: return
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: !.loc43:
  134. // CHECK:STDOUT: return
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: fn @G.1();
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: fn @H.2();
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: fn @I.2() {
  142. // CHECK:STDOUT: !entry:
  143. // CHECK:STDOUT: return
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: fn @G.2() {
  147. // CHECK:STDOUT: !entry:
  148. // CHECK:STDOUT: return
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: