fail_init_with_self.carbon 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/var/no_prelude/fail_init_with_self.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/var/no_prelude/fail_init_with_self.carbon
  10. fn Main() {
  11. // CHECK:STDERR: fail_init_with_self.carbon:[[@LINE+4]]:15: error: `x` used before initialization [UsedBeforeInitialization]
  12. // CHECK:STDERR: var x: () = x;
  13. // CHECK:STDERR: ^
  14. // CHECK:STDERR:
  15. var x: () = x;
  16. }
  17. // CHECK:STDOUT: --- fail_init_with_self.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  21. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  22. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  23. // CHECK:STDOUT: }
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: file {
  26. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  27. // CHECK:STDOUT: .Main = %Main.decl
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: fn @Main() {
  33. // CHECK:STDOUT: !entry:
  34. // CHECK:STDOUT: name_binding_decl {
  35. // CHECK:STDOUT: %x.patt: %empty_tuple.type = binding_pattern x
  36. // CHECK:STDOUT: %.loc16_3: %empty_tuple.type = var_pattern %x.patt
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %x.var: ref %empty_tuple.type = var x
  39. // CHECK:STDOUT: %x.ref: <error> = name_ref x, <error> [template = <error>]
  40. // CHECK:STDOUT: assign %x.var, <error>
  41. // CHECK:STDOUT: %.loc16_11.1: type = splice_block %.loc16_11.3 [template = constants.%empty_tuple.type] {
  42. // CHECK:STDOUT: %.loc16_11.2: %empty_tuple.type = tuple_literal ()
  43. // CHECK:STDOUT: %.loc16_11.3: type = converted %.loc16_11.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %x: ref %empty_tuple.type = bind_name x, %x.var
  46. // CHECK:STDOUT: return
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: