fail_init_with_self.carbon 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/destroy.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/var/fail_init_with_self.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/var/fail_init_with_self.carbon
  14. // --- fail_basic.carbon
  15. fn Main() {
  16. // CHECK:STDERR: fail_basic.carbon:[[@LINE+4]]:15: error: `x` used before initialization [UsedBeforeInitialization]
  17. // CHECK:STDERR: var x: () = x;
  18. // CHECK:STDERR: ^
  19. // CHECK:STDERR:
  20. var x: () = x;
  21. }
  22. // CHECK:STDOUT: --- fail_basic.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  26. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  27. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  28. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  29. // CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
  30. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  31. // CHECK:STDOUT: %DestroyOp.type: type = fn_type @DestroyOp [concrete]
  32. // CHECK:STDOUT: %DestroyOp: %DestroyOp.type = struct_value () [concrete]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: imports {
  36. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  37. // CHECK:STDOUT: .Destroy = %Core.Destroy
  38. // CHECK:STDOUT: import Core//prelude
  39. // CHECK:STDOUT: import Core//prelude/...
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  46. // CHECK:STDOUT: .Core = imports.%Core
  47. // CHECK:STDOUT: .Main = %Main.decl
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core.import = import Core
  50. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: fn @Main() {
  54. // CHECK:STDOUT: !entry:
  55. // CHECK:STDOUT: name_binding_decl {
  56. // CHECK:STDOUT: %x.patt: %pattern_type.cb1 = ref_binding_pattern x [concrete]
  57. // CHECK:STDOUT: %x.var_patt: %pattern_type.cb1 = var_pattern %x.patt [concrete]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %x.var: ref %empty_tuple.type = var %x.var_patt
  60. // CHECK:STDOUT: %x.ref: <error> = name_ref x, <error> [concrete = <error>]
  61. // CHECK:STDOUT: assign %x.var, <error>
  62. // CHECK:STDOUT: %.loc7_11.1: type = splice_block %.loc7_11.3 [concrete = constants.%empty_tuple.type] {
  63. // CHECK:STDOUT: %.loc7_11.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  64. // CHECK:STDOUT: %.loc7_11.3: type = converted %.loc7_11.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %x: ref %empty_tuple.type = ref_binding x, %x.var
  67. // CHECK:STDOUT: %DestroyOp.bound: <bound method> = bound_method %x.var, constants.%DestroyOp
  68. // CHECK:STDOUT: %DestroyOp.call: init %empty_tuple.type = call %DestroyOp.bound(%x.var)
  69. // CHECK:STDOUT: return
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: fn @DestroyOp(%self.param: %empty_tuple.type) = "no_op";
  73. // CHECK:STDOUT: