fail_name_conflict.carbon 4.2 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/alias/no_prelude/fail_name_conflict.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/no_prelude/fail_name_conflict.carbon
  10. class C {}
  11. alias a = C;
  12. // CHECK:STDERR: fail_name_conflict.carbon:[[@LINE+7]]:5: error: duplicate name being declared in the same scope [NameDeclDuplicate]
  13. // CHECK:STDERR: var a: C = {};
  14. // CHECK:STDERR: ^
  15. // CHECK:STDERR: fail_name_conflict.carbon:[[@LINE-4]]:7: note: name is previously declared here [NameDeclPrevious]
  16. // CHECK:STDERR: alias a = C;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR:
  19. var a: C = {};
  20. var b: C = {};
  21. // CHECK:STDERR: fail_name_conflict.carbon:[[@LINE+7]]:7: error: duplicate name being declared in the same scope [NameDeclDuplicate]
  22. // CHECK:STDERR: alias b = C;
  23. // CHECK:STDERR: ^
  24. // CHECK:STDERR: fail_name_conflict.carbon:[[@LINE-4]]:5: note: name is previously declared here [NameDeclPrevious]
  25. // CHECK:STDERR: var b: C = {};
  26. // CHECK:STDERR: ^
  27. // CHECK:STDERR:
  28. alias b = C;
  29. // CHECK:STDOUT: --- fail_name_conflict.carbon
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: constants {
  32. // CHECK:STDOUT: %C: type = class_type @C [template]
  33. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  34. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  35. // CHECK:STDOUT: %C.val: %C = struct_value () [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .C = %C.decl
  41. // CHECK:STDOUT: .a = %a.loc13
  42. // CHECK:STDOUT: .b = %b
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  45. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, %C.decl [template = constants.%C]
  46. // CHECK:STDOUT: %a.loc13: type = bind_alias a, %C.decl [template = constants.%C]
  47. // CHECK:STDOUT: name_binding_decl {
  48. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  49. // CHECK:STDOUT: %.loc21: %C = var_pattern %a.patt
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %a.var: ref %C = var a
  52. // CHECK:STDOUT: %C.ref.loc21: type = name_ref C, %C.decl [template = constants.%C]
  53. // CHECK:STDOUT: %a.loc21: ref %C = bind_name a, %a.var
  54. // CHECK:STDOUT: name_binding_decl {
  55. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  56. // CHECK:STDOUT: %.loc23: %C = var_pattern %b.patt
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %b.var: ref %C = var b
  59. // CHECK:STDOUT: %C.ref.loc23: type = name_ref C, %C.decl [template = constants.%C]
  60. // CHECK:STDOUT: %b: ref %C = bind_name b, %b.var
  61. // CHECK:STDOUT: %C.ref.loc31: type = name_ref C, %C.decl [template = constants.%C]
  62. // CHECK:STDOUT: %.loc31: type = bind_alias <none>, %C.decl [template = constants.%C]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: class @C {
  66. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  67. // CHECK:STDOUT: complete_type_witness = %complete_type
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: !members:
  70. // CHECK:STDOUT: .Self = constants.%C
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @__global_init() {
  74. // CHECK:STDOUT: !entry:
  75. // CHECK:STDOUT: %.loc21_13.1: %empty_struct_type = struct_literal ()
  76. // CHECK:STDOUT: %.loc21_13.2: init %C = class_init (), file.%a.var [template = constants.%C.val]
  77. // CHECK:STDOUT: %.loc21_1: init %C = converted %.loc21_13.1, %.loc21_13.2 [template = constants.%C.val]
  78. // CHECK:STDOUT: assign file.%a.var, %.loc21_1
  79. // CHECK:STDOUT: %.loc23_13.1: %empty_struct_type = struct_literal ()
  80. // CHECK:STDOUT: %.loc23_13.2: init %C = class_init (), file.%b.var [template = constants.%C.val]
  81. // CHECK:STDOUT: %.loc23_1: init %C = converted %.loc23_13.1, %.loc23_13.2 [template = constants.%C.val]
  82. // CHECK:STDOUT: assign file.%b.var, %.loc23_1
  83. // CHECK:STDOUT: return
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: