duplicate_name_same_line.carbon 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/ir/duplicate_name_same_line.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/ir/duplicate_name_same_line.carbon
  10. fn A() { if (true) { var n: i32 = 1; } if (true) { var n: i32 = 2; } }
  11. // CHECK:STDOUT: --- duplicate_name_same_line.carbon
  12. // CHECK:STDOUT:
  13. // CHECK:STDOUT: constants {
  14. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  15. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  16. // CHECK:STDOUT: %true: bool = bool_literal true [template]
  17. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  18. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  19. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  20. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template]
  21. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  22. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  23. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  24. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  25. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template]
  26. // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [template]
  27. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [template]
  28. // CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [template]
  29. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [template]
  30. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [template]
  31. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [template]
  32. // CHECK:STDOUT: %Convert.specific_fn.787: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [template]
  33. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [template]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: imports {
  37. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  38. // CHECK:STDOUT: .Int = %Core.Int
  39. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  40. // CHECK:STDOUT: import Core//prelude
  41. // CHECK:STDOUT: import Core//prelude/...
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Core = imports.%Core
  48. // CHECK:STDOUT: .A = %A.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: fn @A() {
  55. // CHECK:STDOUT: !entry:
  56. // CHECK:STDOUT: %true.loc11_14: bool = bool_literal true [template = constants.%true]
  57. // CHECK:STDOUT: if %true.loc11_14 br !if.then.loc11_18 else br !if.else.loc11_18
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: !if.then.loc11_18:
  60. // CHECK:STDOUT: name_binding_decl {
  61. // CHECK:STDOUT: %n.patt.loc11_26: %i32 = binding_pattern n
  62. // CHECK:STDOUT: %.loc11_22.1: %i32 = var_pattern %n.patt.loc11_26
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %n.var.loc11_22: ref %i32 = var n
  65. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  66. // CHECK:STDOUT: %impl.elem0.loc11_22: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  67. // CHECK:STDOUT: %bound_method.loc11_22: <bound method> = bound_method %int_1, %impl.elem0.loc11_22 [template = constants.%Convert.bound.ab5]
  68. // CHECK:STDOUT: %specific_fn.loc11_22: <specific function> = specific_function %bound_method.loc11_22, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
  69. // CHECK:STDOUT: %int.convert_checked.loc11_22: init %i32 = call %specific_fn.loc11_22(%int_1) [template = constants.%int_1.5d2]
  70. // CHECK:STDOUT: %.loc11_22.2: init %i32 = converted %int_1, %int.convert_checked.loc11_22 [template = constants.%int_1.5d2]
  71. // CHECK:STDOUT: assign %n.var.loc11_22, %.loc11_22.2
  72. // CHECK:STDOUT: %.loc11_29: type = splice_block %i32.loc11_29 [template = constants.%i32] {
  73. // CHECK:STDOUT: %int_32.loc11_29: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  74. // CHECK:STDOUT: %i32.loc11_29: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %n.loc11_26: ref %i32 = bind_name n, %n.var.loc11_22
  77. // CHECK:STDOUT: br !if.else.loc11_18
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: !if.else.loc11_18:
  80. // CHECK:STDOUT: %true.loc11_44: bool = bool_literal true [template = constants.%true]
  81. // CHECK:STDOUT: if %true.loc11_44 br !if.then.loc11_48 else br !if.else.loc11_48
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !if.then.loc11_48:
  84. // CHECK:STDOUT: name_binding_decl {
  85. // CHECK:STDOUT: %n.patt.loc11_56: %i32 = binding_pattern n
  86. // CHECK:STDOUT: %.loc11_52.1: %i32 = var_pattern %n.patt.loc11_56
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %n.var.loc11_52: ref %i32 = var n
  89. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  90. // CHECK:STDOUT: %impl.elem0.loc11_52: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  91. // CHECK:STDOUT: %bound_method.loc11_52: <bound method> = bound_method %int_2, %impl.elem0.loc11_52 [template = constants.%Convert.bound.ef9]
  92. // CHECK:STDOUT: %specific_fn.loc11_52: <specific function> = specific_function %bound_method.loc11_52, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.787]
  93. // CHECK:STDOUT: %int.convert_checked.loc11_52: init %i32 = call %specific_fn.loc11_52(%int_2) [template = constants.%int_2.ef8]
  94. // CHECK:STDOUT: %.loc11_52.2: init %i32 = converted %int_2, %int.convert_checked.loc11_52 [template = constants.%int_2.ef8]
  95. // CHECK:STDOUT: assign %n.var.loc11_52, %.loc11_52.2
  96. // CHECK:STDOUT: %.loc11_59: type = splice_block %i32.loc11_59 [template = constants.%i32] {
  97. // CHECK:STDOUT: %int_32.loc11_59: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  98. // CHECK:STDOUT: %i32.loc11_59: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: %n.loc11_56: ref %i32 = bind_name n, %n.var.loc11_52
  101. // CHECK:STDOUT: br !if.else.loc11_48
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: !if.else.loc11_48:
  104. // CHECK:STDOUT: return
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: