fail_duplicate_decl.carbon 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/destroy.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/var/fail_duplicate_decl.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/var/fail_duplicate_decl.carbon
  14. // --- fail_basic.carbon
  15. fn Main() {
  16. var x: () = ();
  17. // CHECK:STDERR: fail_basic.carbon:[[@LINE+7]]:7: error: duplicate name `x` being declared in the same scope [NameDeclDuplicate]
  18. // CHECK:STDERR: var x: () = ();
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR: fail_basic.carbon:[[@LINE-4]]:7: note: name is previously declared here [NameDeclPrevious]
  21. // CHECK:STDERR: var x: () = ();
  22. // CHECK:STDERR: ^
  23. // CHECK:STDERR:
  24. var x: () = ();
  25. }
  26. // CHECK:STDOUT: --- fail_basic.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  30. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  31. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  32. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  33. // CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
  34. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  35. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  36. // CHECK:STDOUT: %facet_value: %type_where = facet_value %empty_tuple.type, () [concrete]
  37. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bb8: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
  38. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.72f: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bb8 = struct_value () [concrete]
  39. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %DestroyT.binding.as_type.as.Destroy.impl.Op.72f, @DestroyT.binding.as_type.as.Destroy.impl.Op(%facet_value) [concrete]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  44. // CHECK:STDOUT: .Destroy = %Core.Destroy
  45. // CHECK:STDOUT: import Core//prelude
  46. // CHECK:STDOUT: import Core//prelude/...
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  53. // CHECK:STDOUT: .Core = imports.%Core
  54. // CHECK:STDOUT: .Main = %Main.decl
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.import = import Core
  57. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @Main() {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: name_binding_decl {
  63. // CHECK:STDOUT: %x.patt.loc3: %pattern_type.cb1 = ref_binding_pattern x [concrete]
  64. // CHECK:STDOUT: %x.var_patt.loc3: %pattern_type.cb1 = var_pattern %x.patt.loc3 [concrete]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %x.var.loc3: ref %empty_tuple.type = var %x.var_patt.loc3
  67. // CHECK:STDOUT: %.loc3_16.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  68. // CHECK:STDOUT: %.loc3_16.2: init %empty_tuple.type = tuple_init () to %x.var.loc3 [concrete = constants.%empty_tuple]
  69. // CHECK:STDOUT: %.loc3_3: init %empty_tuple.type = converted %.loc3_16.1, %.loc3_16.2 [concrete = constants.%empty_tuple]
  70. // CHECK:STDOUT: assign %x.var.loc3, %.loc3_3
  71. // CHECK:STDOUT: %.loc3_11.1: type = splice_block %.loc3_11.3 [concrete = constants.%empty_tuple.type] {
  72. // CHECK:STDOUT: %.loc3_11.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  73. // CHECK:STDOUT: %.loc3_11.3: type = converted %.loc3_11.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %x.loc3: ref %empty_tuple.type = ref_binding x, %x.var.loc3
  76. // CHECK:STDOUT: name_binding_decl {
  77. // CHECK:STDOUT: %x.patt.loc11: %pattern_type.cb1 = ref_binding_pattern x [concrete]
  78. // CHECK:STDOUT: %x.var_patt.loc11: %pattern_type.cb1 = var_pattern %x.patt.loc11 [concrete]
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %x.var.loc11: ref %empty_tuple.type = var %x.var_patt.loc11
  81. // CHECK:STDOUT: %.loc11_16.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  82. // CHECK:STDOUT: %.loc11_16.2: init %empty_tuple.type = tuple_init () to %x.var.loc11 [concrete = constants.%empty_tuple]
  83. // CHECK:STDOUT: %.loc11_3: init %empty_tuple.type = converted %.loc11_16.1, %.loc11_16.2 [concrete = constants.%empty_tuple]
  84. // CHECK:STDOUT: assign %x.var.loc11, %.loc11_3
  85. // CHECK:STDOUT: %.loc11_11.1: type = splice_block %.loc11_11.3 [concrete = constants.%empty_tuple.type] {
  86. // CHECK:STDOUT: %.loc11_11.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  87. // CHECK:STDOUT: %.loc11_11.3: type = converted %.loc11_11.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %x.loc11: ref %empty_tuple.type = ref_binding x, %x.var.loc11
  90. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound.loc11: <bound method> = bound_method %x.var.loc11, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f
  91. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn.1: <specific function> = specific_function constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f, @DestroyT.binding.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn]
  92. // CHECK:STDOUT: %bound_method.loc11: <bound method> = bound_method %x.var.loc11, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn.1
  93. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call.loc11: init %empty_tuple.type = call %bound_method.loc11(%x.var.loc11)
  94. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound.loc3: <bound method> = bound_method %x.var.loc3, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f
  95. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn.2: <specific function> = specific_function constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f, @DestroyT.binding.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn]
  96. // CHECK:STDOUT: %bound_method.loc3: <bound method> = bound_method %x.var.loc3, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn.2
  97. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call.loc3: init %empty_tuple.type = call %bound_method.loc3(%x.var.loc3)
  98. // CHECK:STDOUT: return
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: