duplicate_name_same_line.carbon 5.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.1: Core.IntLiteral = int_value 1 [template]
  20. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  21. // CHECK:STDOUT: %Convert.type.10: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  22. // CHECK:STDOUT: %Convert.10: %Convert.type.10 = struct_value () [template]
  23. // CHECK:STDOUT: %interface.5: <witness> = interface_witness (%Convert.10) [template]
  24. // CHECK:STDOUT: %Convert.bound.1: <bound method> = bound_method %int_1.1, %Convert.10 [template]
  25. // CHECK:STDOUT: %Convert.specific_fn.1: <specific function> = specific_function %Convert.bound.1, @Convert.2(%int_32) [template]
  26. // CHECK:STDOUT: %int_1.2: %i32 = int_value 1 [template]
  27. // CHECK:STDOUT: %int_2.1: Core.IntLiteral = int_value 2 [template]
  28. // CHECK:STDOUT: %Convert.bound.2: <bound method> = bound_method %int_2.1, %Convert.10 [template]
  29. // CHECK:STDOUT: %Convert.specific_fn.2: <specific function> = specific_function %Convert.bound.2, @Convert.2(%int_32) [template]
  30. // CHECK:STDOUT: %int_2.2: %i32 = int_value 2 [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  35. // CHECK:STDOUT: .Int = %import_ref.1
  36. // CHECK:STDOUT: .ImplicitAs = %import_ref.5
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .A = %A.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: fn @A() {
  52. // CHECK:STDOUT: !entry:
  53. // CHECK:STDOUT: %true.loc11_14: bool = bool_literal true [template = constants.%true]
  54. // CHECK:STDOUT: if %true.loc11_14 br !if.then.loc11_18 else br !if.else.loc11_18
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: !if.then.loc11_18:
  57. // CHECK:STDOUT: %n.var.loc11_26: ref %i32 = var n
  58. // CHECK:STDOUT: %n.loc11_26: ref %i32 = bind_name n, %n.var.loc11_26
  59. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  60. // CHECK:STDOUT: %impl.elem0.loc11_36: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  61. // CHECK:STDOUT: %Convert.bound.loc11_36: <bound method> = bound_method %int_1, %impl.elem0.loc11_36 [template = constants.%Convert.bound.1]
  62. // CHECK:STDOUT: %Convert.specific_fn.loc11_36: <specific function> = specific_function %Convert.bound.loc11_36, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.1]
  63. // CHECK:STDOUT: %int.convert_checked.loc11_36: init %i32 = call %Convert.specific_fn.loc11_36(%int_1) [template = constants.%int_1.2]
  64. // CHECK:STDOUT: %.loc11_36: init %i32 = converted %int_1, %int.convert_checked.loc11_36 [template = constants.%int_1.2]
  65. // CHECK:STDOUT: assign %n.var.loc11_26, %.loc11_36
  66. // CHECK:STDOUT: br !if.else.loc11_18
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: !if.else.loc11_18:
  69. // CHECK:STDOUT: %true.loc11_44: bool = bool_literal true [template = constants.%true]
  70. // CHECK:STDOUT: if %true.loc11_44 br !if.then.loc11_48 else br !if.else.loc11_48
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !if.then.loc11_48:
  73. // CHECK:STDOUT: %n.var.loc11_56: ref %i32 = var n
  74. // CHECK:STDOUT: %n.loc11_56: ref %i32 = bind_name n, %n.var.loc11_56
  75. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.1]
  76. // CHECK:STDOUT: %impl.elem0.loc11_66: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  77. // CHECK:STDOUT: %Convert.bound.loc11_66: <bound method> = bound_method %int_2, %impl.elem0.loc11_66 [template = constants.%Convert.bound.2]
  78. // CHECK:STDOUT: %Convert.specific_fn.loc11_66: <specific function> = specific_function %Convert.bound.loc11_66, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.2]
  79. // CHECK:STDOUT: %int.convert_checked.loc11_66: init %i32 = call %Convert.specific_fn.loc11_66(%int_2) [template = constants.%int_2.2]
  80. // CHECK:STDOUT: %.loc11_66: init %i32 = converted %int_2, %int.convert_checked.loc11_66 [template = constants.%int_2.2]
  81. // CHECK:STDOUT: assign %n.var.loc11_56, %.loc11_66
  82. // CHECK:STDOUT: br !if.else.loc11_48
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !if.else.loc11_48:
  85. // CHECK:STDOUT: return
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: