fail_use_in_init.carbon 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/int.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/let/fail_use_in_init.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/fail_use_in_init.carbon
  14. fn F() {
  15. // CHECK:STDERR: fail_use_in_init.carbon:[[@LINE+4]]:16: error: `a` used before initialization [UsedBeforeInitialization]
  16. // CHECK:STDERR: let a: i32 = a;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR:
  19. let a: i32 = a;
  20. }
  21. // CHECK:STDOUT: --- fail_use_in_init.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  26. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  27. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  28. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  30. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  35. // CHECK:STDOUT: .Int = %Core.Int
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/...
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .F = %F.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: fn @F() {
  52. // CHECK:STDOUT: !entry:
  53. // CHECK:STDOUT: name_binding_decl {
  54. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %a.ref: <error> = name_ref a, <error> [concrete = <error>]
  57. // CHECK:STDOUT: %.loc20: type = splice_block %i32 [concrete = constants.%i32] {
  58. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  59. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %a: %i32 = value_binding a, <error> [concrete = <error>]
  62. // CHECK:STDOUT: return
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: