fail_redefinition.carbon 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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: 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: 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: type = class_type @.1 [template]
  54. // CHECK:STDOUT: %G.type.1: type = fn_type @G.1 [template]
  55. // CHECK:STDOUT: %G.1: %G.type.1 = struct_value () [template]
  56. // CHECK:STDOUT: %H.type.2: type = fn_type @H.2 [template]
  57. // CHECK:STDOUT: %H.2: %H.type.2 = struct_value () [template]
  58. // CHECK:STDOUT: %I.type.2: type = fn_type @I.2 [template]
  59. // CHECK:STDOUT: %I.2: %I.type.2 = struct_value () [template]
  60. // CHECK:STDOUT: %G.type.2: type = fn_type @G.2 [template]
  61. // CHECK:STDOUT: %G.2: %G.type.2 = struct_value () [template]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: file {
  65. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  66. // CHECK:STDOUT: .Core = %Core
  67. // CHECK:STDOUT: .Class = %Class.decl
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  70. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  71. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.3] {}
  72. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  73. // CHECK:STDOUT: %G.decl: %G.type.2 = fn_decl @G.2 [template = constants.%G.2] {}
  74. // CHECK:STDOUT: %H.decl: %H.type.1 = fn_decl @H.1 [template = constants.%H.1] {}
  75. // CHECK:STDOUT: %I.decl: %I.type.1 = fn_decl @I.1 [template = constants.%I.1] {}
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: class @Class {
  79. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  80. // CHECK:STDOUT: %H.decl: %H.type.1 = fn_decl @H.1 [template = constants.%H.1] {}
  81. // CHECK:STDOUT: %I.decl: %I.type.1 = fn_decl @I.1 [template = constants.%I.1] {}
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !members:
  84. // CHECK:STDOUT: .Self = constants.%Class
  85. // CHECK:STDOUT: .F = %F.decl
  86. // CHECK:STDOUT: .H = %H.decl
  87. // CHECK:STDOUT: .I = %I.decl
  88. // CHECK:STDOUT: .G = file.%G.decl
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: class @.1 {
  92. // CHECK:STDOUT: %G.decl: %G.type.1 = fn_decl @G.1 [template = constants.%G.1] {}
  93. // CHECK:STDOUT: %H.decl: %H.type.2 = fn_decl @H.2 [template = constants.%H.2] {}
  94. // CHECK:STDOUT: %I.decl: %I.type.2 = fn_decl @I.2 [template = constants.%I.2] {}
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: !members:
  97. // CHECK:STDOUT: .Self = constants.%.3
  98. // CHECK:STDOUT: .G = %G.decl
  99. // CHECK:STDOUT: .H = %H.decl
  100. // CHECK:STDOUT: .I = %I.decl
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: fn @F() {
  104. // CHECK:STDOUT: !entry:
  105. // CHECK:STDOUT: return
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: fn @H.1() {
  109. // CHECK:STDOUT: !entry:
  110. // CHECK:STDOUT: return
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @I.1() {
  114. // CHECK:STDOUT: !entry:
  115. // CHECK:STDOUT: return
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: !.loc43:
  118. // CHECK:STDOUT: return
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: fn @G.1();
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: fn @H.2();
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: fn @I.2() {
  126. // CHECK:STDOUT: !entry:
  127. // CHECK:STDOUT: return
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: fn @G.2() {
  131. // CHECK:STDOUT: !entry:
  132. // CHECK:STDOUT: return
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT: