scoped.carbon 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/enum/scoped.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/enum/scoped.carbon
  12. // --- enum.h
  13. enum class Enum : short { a, b, c };
  14. // --- import_enum.carbon
  15. library "[[@TEST_NAME]]";
  16. import Cpp library "enum.h";
  17. //@dump-sem-ir-begin
  18. fn F() {
  19. let a: Cpp.Enum = Cpp.Enum.a;
  20. }
  21. //@dump-sem-ir-end
  22. // --- fail_name_without_scope.carbon
  23. library "[[@TEST_NAME]]";
  24. import Cpp library "enum.h";
  25. fn F() {
  26. // CHECK:STDERR: fail_name_without_scope.carbon:[[@LINE+4]]:21: error: member name `b` not found in `Cpp` [MemberNameNotFoundInInstScope]
  27. // CHECK:STDERR: let b: Cpp.Enum = Cpp.b;
  28. // CHECK:STDERR: ^~~~~
  29. // CHECK:STDERR:
  30. let b: Cpp.Enum = Cpp.b;
  31. }
  32. // CHECK:STDOUT: --- import_enum.carbon
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: constants {
  35. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  36. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  37. // CHECK:STDOUT: %Enum: type = class_type @Enum [concrete]
  38. // CHECK:STDOUT: %pattern_type: type = pattern_type %Enum [concrete]
  39. // CHECK:STDOUT: %int_0: %Enum = int_value 0 [concrete]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  44. // CHECK:STDOUT: .Enum = %Enum.decl
  45. // CHECK:STDOUT: import Cpp//...
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Enum.decl: type = class_decl @Enum [concrete = constants.%Enum] {} {}
  48. // CHECK:STDOUT: %int_0: %Enum = int_value 0 [concrete = constants.%int_0]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @F() {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: name_binding_decl {
  58. // CHECK:STDOUT: %a.patt: %pattern_type = value_binding_pattern a [concrete]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Cpp.ref.loc8_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  61. // CHECK:STDOUT: %Enum.ref.loc8_24: type = name_ref Enum, imports.%Enum.decl [concrete = constants.%Enum]
  62. // CHECK:STDOUT: %a.ref: %Enum = name_ref a, imports.%int_0 [concrete = constants.%int_0]
  63. // CHECK:STDOUT: %.loc8: type = splice_block %Enum.ref.loc8_13 [concrete = constants.%Enum] {
  64. // CHECK:STDOUT: %Cpp.ref.loc8_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  65. // CHECK:STDOUT: %Enum.ref.loc8_13: type = name_ref Enum, imports.%Enum.decl [concrete = constants.%Enum]
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %a: %Enum = value_binding a, %a.ref
  68. // CHECK:STDOUT: return
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: