fail_conflict_imported_namespace_second.carbon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/namespace/fail_conflict_imported_namespace_second.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon
  10. // --- fn.carbon
  11. package Example library "[[@TEST_NAME]]";
  12. fn NS();
  13. // --- fail_conflict.carbon
  14. package Example;
  15. import library "fn";
  16. // CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope
  17. // CHECK:STDERR: namespace NS;
  18. // CHECK:STDERR: ^~~~~~~~~~~~~
  19. // CHECK:STDERR: fail_conflict.carbon:[[@LINE-5]]:1: in import
  20. // CHECK:STDERR: fn.carbon:4:1: note: name is previously declared here
  21. // CHECK:STDERR: fn NS();
  22. // CHECK:STDERR: ^~~~~~~~
  23. // CHECK:STDERR:
  24. namespace NS;
  25. // CHECK:STDERR: fail_conflict.carbon:[[@LINE+7]]:4: error: name qualifiers are only allowed for entities that provide a scope
  26. // CHECK:STDERR: fn NS.Foo();
  27. // CHECK:STDERR: ^~
  28. // CHECK:STDERR: fail_conflict.carbon:[[@LINE-15]]:1: in import
  29. // CHECK:STDERR: fn.carbon:4:1: note: referenced non-scope entity declared here
  30. // CHECK:STDERR: fn NS();
  31. // CHECK:STDERR: ^~~~~~~~
  32. fn NS.Foo();
  33. // CHECK:STDOUT: --- fn.carbon
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: constants {
  36. // CHECK:STDOUT: %NS.type: type = fn_type @NS [template]
  37. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  38. // CHECK:STDOUT: %NS: %NS.type = struct_value () [template]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: imports {
  42. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  43. // CHECK:STDOUT: import Core//prelude
  44. // CHECK:STDOUT: import Core//prelude/operators
  45. // CHECK:STDOUT: import Core//prelude/types
  46. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  47. // CHECK:STDOUT: import Core//prelude/operators/as
  48. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  49. // CHECK:STDOUT: import Core//prelude/operators/comparison
  50. // CHECK:STDOUT: import Core//prelude/types/bool
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  56. // CHECK:STDOUT: .Core = imports.%Core
  57. // CHECK:STDOUT: .NS = %NS.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.import = import Core
  60. // CHECK:STDOUT: %NS.decl: %NS.type = fn_decl @NS [template = constants.%NS] {} {}
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @NS();
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: --- fail_conflict.carbon
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: constants {
  68. // CHECK:STDOUT: %NS.type: type = fn_type @NS [template]
  69. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  70. // CHECK:STDOUT: %NS: %NS.type = struct_value () [template]
  71. // CHECK:STDOUT: %.type: type = fn_type @.1 [template]
  72. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: imports {
  76. // CHECK:STDOUT: %import_ref: %NS.type = import_ref Example//fn, inst+3, loaded [template = constants.%NS]
  77. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  78. // CHECK:STDOUT: import Core//prelude
  79. // CHECK:STDOUT: import Core//prelude/operators
  80. // CHECK:STDOUT: import Core//prelude/types
  81. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  82. // CHECK:STDOUT: import Core//prelude/operators/as
  83. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  84. // CHECK:STDOUT: import Core//prelude/operators/comparison
  85. // CHECK:STDOUT: import Core//prelude/types/bool
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: file {
  90. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  91. // CHECK:STDOUT: .NS = imports.%import_ref
  92. // CHECK:STDOUT: .Core = imports.%Core
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %Core.import = import Core
  95. // CHECK:STDOUT: %default.import = import <invalid>
  96. // CHECK:STDOUT: %.loc14: <namespace> = namespace [template] {}
  97. // CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [template = constants.%.2] {} {}
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: fn @NS();
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @.1();
  103. // CHECK:STDOUT: