fail_conflict_no_namespaces.carbon 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/packages/fail_conflict_no_namespaces.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/packages/fail_conflict_no_namespaces.carbon
  10. // --- fn.carbon
  11. package Example library "fn";
  12. fn Foo();
  13. // --- var.carbon
  14. package Example library "var";
  15. var Foo: i32;
  16. // --- fail_conflict.carbon
  17. package Example library "conflict";
  18. import library "fn";
  19. // CHECK:STDERR: fail_conflict.carbon:[[@LINE+12]]:1: In import.
  20. // CHECK:STDERR: import library "var";
  21. // CHECK:STDERR: ^~~~~~
  22. // CHECK:STDERR: var.carbon:4:5: ERROR: Duplicate name being declared in the same scope.
  23. // CHECK:STDERR: var Foo: i32;
  24. // CHECK:STDERR: ^~~
  25. // CHECK:STDERR: fail_conflict.carbon:[[@LINE-7]]:1: In import.
  26. // CHECK:STDERR: import library "fn";
  27. // CHECK:STDERR: ^~~~~~
  28. // CHECK:STDERR: fn.carbon:4:1: Name is previously declared here.
  29. // CHECK:STDERR: fn Foo();
  30. // CHECK:STDERR: ^~~~~~~~~
  31. import library "var";
  32. // CHECK:STDOUT: --- fn.carbon
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: constants {
  35. // CHECK:STDOUT: %Foo.type: type = fn_type @Foo [template]
  36. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  37. // CHECK:STDOUT: %Foo: %Foo.type = struct_value () [template]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: file {
  41. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  42. // CHECK:STDOUT: .Core = %Core
  43. // CHECK:STDOUT: .Foo = %Foo.decl
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  46. // CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [template = constants.%Foo] {}
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: fn @Foo();
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: --- var.carbon
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: constants {
  54. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  55. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  56. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: file {
  60. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  61. // CHECK:STDOUT: .Core = %Core
  62. // CHECK:STDOUT: .Foo = %Foo
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  65. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  66. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc4_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  68. // CHECK:STDOUT: %.loc4_10.2: type = converted %int.make_type_32, %.loc4_10.1 [template = i32]
  69. // CHECK:STDOUT: %Foo.var: ref i32 = var Foo
  70. // CHECK:STDOUT: %Foo: ref i32 = bind_name Foo, %Foo.var
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: --- fail_conflict.carbon
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: file {
  78. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  79. // CHECK:STDOUT: .Foo = %import_ref.1
  80. // CHECK:STDOUT: .Core = %Core
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+2, unloaded
  83. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+12, unloaded
  84. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: