fail_decl_in_alias.carbon 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_decl_in_alias.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/fail_decl_in_alias.carbon
  10. namespace NS;
  11. alias ns = NS;
  12. // Aliases can't be used when declaring names.
  13. // CHECK:STDERR: fail_decl_in_alias.carbon:[[@LINE+7]]:4: error: name qualifiers are only allowed for entities that provide a scope [QualifiedNameInNonScope]
  14. // CHECK:STDERR: fn ns.A() -> i32 { return 0; }
  15. // CHECK:STDERR: ^~
  16. // CHECK:STDERR: fail_decl_in_alias.carbon:[[@LINE-6]]:7: note: referenced non-scope entity declared here [QualifiedNameNonScopeEntity]
  17. // CHECK:STDERR: alias ns = NS;
  18. // CHECK:STDERR: ^~
  19. // CHECK:STDERR:
  20. fn ns.A() -> i32 { return 0; }
  21. // CHECK:STDOUT: --- fail_decl_in_alias.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  25. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  26. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  27. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  28. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  29. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  30. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  31. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.4f9(%int_32) [concrete]
  32. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  33. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  34. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%impl_witness.d39) [concrete]
  35. // CHECK:STDOUT: %.be7: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  36. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.956 [concrete]
  37. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  38. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
  39. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  44. // CHECK:STDOUT: .Int = %Core.Int
  45. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  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: .NS = %NS
  55. // CHECK:STDOUT: .ns = %ns
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core.import = import Core
  58. // CHECK:STDOUT: %NS: <namespace> = namespace [concrete] {}
  59. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, %NS [concrete = %NS]
  60. // CHECK:STDOUT: %ns: <namespace> = bind_alias ns, %NS [concrete = %NS]
  61. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [concrete = constants.%A] {
  62. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  63. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param0
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  66. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  67. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  68. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: fn @A() -> %i32 {
  73. // CHECK:STDOUT: !entry:
  74. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  75. // CHECK:STDOUT: %impl.elem0: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  76. // CHECK:STDOUT: %bound_method.loc23_28.1: <bound method> = bound_method %int_0, %impl.elem0 [concrete = constants.%Convert.bound]
  77. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  78. // CHECK:STDOUT: %bound_method.loc23_28.2: <bound method> = bound_method %int_0, %specific_fn [concrete = constants.%bound_method]
  79. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc23_28.2(%int_0) [concrete = constants.%int_0.6a9]
  80. // CHECK:STDOUT: %.loc23_28.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_0.6a9]
  81. // CHECK:STDOUT: %.loc23_28.2: %i32 = converted %int_0, %.loc23_28.1 [concrete = constants.%int_0.6a9]
  82. // CHECK:STDOUT: return %.loc23_28.2
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: