fail_duplicate_name.carbon 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/struct/fail_duplicate_name.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/fail_duplicate_name.carbon
  10. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+7]]:42: ERROR: Duplicated field name `abc` in struct type literal.
  11. // CHECK:STDERR: fn F() -> {.d: i32, .abc: i32, .e: i32, .abc: i32, .f: i32};
  12. // CHECK:STDERR: ^~~
  13. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+4]]:22: Field with the same name here.
  14. // CHECK:STDERR: fn F() -> {.d: i32, .abc: i32, .e: i32, .abc: i32, .f: i32};
  15. // CHECK:STDERR: ^~~
  16. // CHECK:STDERR:
  17. fn F() -> {.d: i32, .abc: i32, .e: i32, .abc: i32, .f: i32};
  18. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+7]]:19: ERROR: Duplicated field name `a` in struct type literal.
  19. // CHECK:STDERR: let v: {.a: i32, .a: i32} = {.a = 1};
  20. // CHECK:STDERR: ^
  21. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+4]]:10: Field with the same name here.
  22. // CHECK:STDERR: let v: {.a: i32, .a: i32} = {.a = 1};
  23. // CHECK:STDERR: ^
  24. // CHECK:STDERR:
  25. let v: {.a: i32, .a: i32} = {.a = 1};
  26. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+7]]:26: ERROR: Duplicated field name `def` in struct literal.
  27. // CHECK:STDERR: let w: i32 = {.def = 1, .def = 2}.def;
  28. // CHECK:STDERR: ^~~
  29. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+4]]:16: Field with the same name here.
  30. // CHECK:STDERR: let w: i32 = {.def = 1, .def = 2}.def;
  31. // CHECK:STDERR: ^~~
  32. // CHECK:STDERR:
  33. let w: i32 = {.def = 1, .def = 2}.def;
  34. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+7]]:30: ERROR: Duplicated field name `a` in struct literal.
  35. // CHECK:STDERR: var x: {.a: i32} = {.a = 1, .a = 2};
  36. // CHECK:STDERR: ^
  37. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+4]]:22: Field with the same name here.
  38. // CHECK:STDERR: var x: {.a: i32} = {.a = 1, .a = 2};
  39. // CHECK:STDERR: ^
  40. // CHECK:STDERR:
  41. var x: {.a: i32} = {.a = 1, .a = 2};
  42. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+6]]:39: ERROR: Duplicated field name `b` in struct literal.
  43. // CHECK:STDERR: var y: {.b: i32, .c: i32} = {.b = 3, .b = 4};
  44. // CHECK:STDERR: ^
  45. // CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+3]]:31: Field with the same name here.
  46. // CHECK:STDERR: var y: {.b: i32, .c: i32} = {.b = 3, .b = 4};
  47. // CHECK:STDERR: ^
  48. var y: {.b: i32, .c: i32} = {.b = 3, .b = 4};
  49. // CHECK:STDOUT: --- fail_duplicate_name.carbon
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: constants {
  52. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  53. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  54. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  55. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  56. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  57. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  58. // CHECK:STDOUT: %.3: type = struct_type {.a: i32} [template]
  59. // CHECK:STDOUT: %.4: i32 = int_literal 2 [template]
  60. // CHECK:STDOUT: %.5: type = struct_type {.b: i32, .c: i32} [template]
  61. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  62. // CHECK:STDOUT: %.7: i32 = int_literal 3 [template]
  63. // CHECK:STDOUT: %.8: i32 = int_literal 4 [template]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: imports {
  67. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  68. // CHECK:STDOUT: .Int32 = %import_ref
  69. // CHECK:STDOUT: import Core//prelude
  70. // CHECK:STDOUT: import Core//prelude/operators
  71. // CHECK:STDOUT: import Core//prelude/types
  72. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  73. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  74. // CHECK:STDOUT: import Core//prelude/operators/comparison
  75. // CHECK:STDOUT: import Core//prelude/types/bool
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: file {
  81. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  82. // CHECK:STDOUT: .Core = imports.%Core
  83. // CHECK:STDOUT: .F = %F.decl
  84. // CHECK:STDOUT: .v = @__global_init.%v
  85. // CHECK:STDOUT: .w = @__global_init.%w
  86. // CHECK:STDOUT: .x = %x
  87. // CHECK:STDOUT: .y = %y
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %Core.import = import Core
  90. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  91. // CHECK:STDOUT: %int.make_type_32.loc18_16: init type = call constants.%Int32() [template = i32]
  92. // CHECK:STDOUT: %.loc18_16.1: type = value_of_initializer %int.make_type_32.loc18_16 [template = i32]
  93. // CHECK:STDOUT: %.loc18_16.2: type = converted %int.make_type_32.loc18_16, %.loc18_16.1 [template = i32]
  94. // CHECK:STDOUT: %int.make_type_32.loc18_27: init type = call constants.%Int32() [template = i32]
  95. // CHECK:STDOUT: %.loc18_27.1: type = value_of_initializer %int.make_type_32.loc18_27 [template = i32]
  96. // CHECK:STDOUT: %.loc18_27.2: type = converted %int.make_type_32.loc18_27, %.loc18_27.1 [template = i32]
  97. // CHECK:STDOUT: %int.make_type_32.loc18_36: init type = call constants.%Int32() [template = i32]
  98. // CHECK:STDOUT: %.loc18_36.1: type = value_of_initializer %int.make_type_32.loc18_36 [template = i32]
  99. // CHECK:STDOUT: %.loc18_36.2: type = converted %int.make_type_32.loc18_36, %.loc18_36.1 [template = i32]
  100. // CHECK:STDOUT: %int.make_type_32.loc18_47: init type = call constants.%Int32() [template = i32]
  101. // CHECK:STDOUT: %.loc18_47.1: type = value_of_initializer %int.make_type_32.loc18_47 [template = i32]
  102. // CHECK:STDOUT: %.loc18_47.2: type = converted %int.make_type_32.loc18_47, %.loc18_47.1 [template = i32]
  103. // CHECK:STDOUT: %int.make_type_32.loc18_56: init type = call constants.%Int32() [template = i32]
  104. // CHECK:STDOUT: %.loc18_56.1: type = value_of_initializer %int.make_type_32.loc18_56 [template = i32]
  105. // CHECK:STDOUT: %.loc18_56.2: type = converted %int.make_type_32.loc18_56, %.loc18_56.1 [template = i32]
  106. // CHECK:STDOUT: @F.%return: ref <error> = var <return slot>
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %int.make_type_32.loc27_13: init type = call constants.%Int32() [template = i32]
  109. // CHECK:STDOUT: %.loc27_13.1: type = value_of_initializer %int.make_type_32.loc27_13 [template = i32]
  110. // CHECK:STDOUT: %.loc27_13.2: type = converted %int.make_type_32.loc27_13, %.loc27_13.1 [template = i32]
  111. // CHECK:STDOUT: %int.make_type_32.loc27_22: init type = call constants.%Int32() [template = i32]
  112. // CHECK:STDOUT: %.loc27_22.1: type = value_of_initializer %int.make_type_32.loc27_22 [template = i32]
  113. // CHECK:STDOUT: %.loc27_22.2: type = converted %int.make_type_32.loc27_22, %.loc27_22.1 [template = i32]
  114. // CHECK:STDOUT: %int.make_type_32.loc36: init type = call constants.%Int32() [template = i32]
  115. // CHECK:STDOUT: %.loc36_8.1: type = value_of_initializer %int.make_type_32.loc36 [template = i32]
  116. // CHECK:STDOUT: %.loc36_8.2: type = converted %int.make_type_32.loc36, %.loc36_8.1 [template = i32]
  117. // CHECK:STDOUT: %int.make_type_32.loc45: init type = call constants.%Int32() [template = i32]
  118. // CHECK:STDOUT: %.loc45_13.1: type = value_of_initializer %int.make_type_32.loc45 [template = i32]
  119. // CHECK:STDOUT: %.loc45_13.2: type = converted %int.make_type_32.loc45, %.loc45_13.1 [template = i32]
  120. // CHECK:STDOUT: %.loc45_16: type = struct_type {.a: i32} [template = constants.%.3]
  121. // CHECK:STDOUT: %x.var: ref %.3 = var x
  122. // CHECK:STDOUT: %x: ref %.3 = bind_name x, %x.var
  123. // CHECK:STDOUT: %int.make_type_32.loc53_13: init type = call constants.%Int32() [template = i32]
  124. // CHECK:STDOUT: %.loc53_13.1: type = value_of_initializer %int.make_type_32.loc53_13 [template = i32]
  125. // CHECK:STDOUT: %.loc53_13.2: type = converted %int.make_type_32.loc53_13, %.loc53_13.1 [template = i32]
  126. // CHECK:STDOUT: %int.make_type_32.loc53_22: init type = call constants.%Int32() [template = i32]
  127. // CHECK:STDOUT: %.loc53_22.1: type = value_of_initializer %int.make_type_32.loc53_22 [template = i32]
  128. // CHECK:STDOUT: %.loc53_22.2: type = converted %int.make_type_32.loc53_22, %.loc53_22.1 [template = i32]
  129. // CHECK:STDOUT: %.loc53_25: type = struct_type {.b: i32, .c: i32} [template = constants.%.5]
  130. // CHECK:STDOUT: %y.var: ref %.5 = var y
  131. // CHECK:STDOUT: %y: ref %.5 = bind_name y, %y.var
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: fn @F() -> <error>;
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: fn @__global_init() {
  139. // CHECK:STDOUT: !entry:
  140. // CHECK:STDOUT: %.loc27_35: i32 = int_literal 1 [template = constants.%.2]
  141. // CHECK:STDOUT: %.loc27_36: %.3 = struct_literal (%.loc27_35)
  142. // CHECK:STDOUT: %v: <error> = bind_name v, <error>
  143. // CHECK:STDOUT: %.loc36_22: i32 = int_literal 1 [template = constants.%.2]
  144. // CHECK:STDOUT: %.loc36_32: i32 = int_literal 2 [template = constants.%.4]
  145. // CHECK:STDOUT: %w: i32 = bind_name w, <error>
  146. // CHECK:STDOUT: %.loc45_26: i32 = int_literal 1 [template = constants.%.2]
  147. // CHECK:STDOUT: %.loc45_34: i32 = int_literal 2 [template = constants.%.4]
  148. // CHECK:STDOUT: assign file.%x.var, <error>
  149. // CHECK:STDOUT: %.loc53_35: i32 = int_literal 3 [template = constants.%.7]
  150. // CHECK:STDOUT: %.loc53_43: i32 = int_literal 4 [template = constants.%.8]
  151. // CHECK:STDOUT: assign file.%y.var, <error>
  152. // CHECK:STDOUT: return
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT: