fail_error_recovery.carbon 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/full.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/operators/overloaded/fail_error_recovery.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/fail_error_recovery.carbon
  14. // Each of these should only produce one error, and shouldn't complain that
  15. // `<error>` doesn't implement an operator.
  16. fn F() {
  17. // CHECK:STDERR: fail_error_recovery.carbon:[[@LINE+4]]:3: error: name `undeclared` not found [NameNotFound]
  18. // CHECK:STDERR: undeclared + 1;
  19. // CHECK:STDERR: ^~~~~~~~~~
  20. // CHECK:STDERR:
  21. undeclared + 1;
  22. }
  23. fn G(n: i32) {
  24. // CHECK:STDERR: fail_error_recovery.carbon:[[@LINE+4]]:7: error: name `undeclared` not found [NameNotFound]
  25. // CHECK:STDERR: n + undeclared;
  26. // CHECK:STDERR: ^~~~~~~~~~
  27. // CHECK:STDERR:
  28. n + undeclared;
  29. }
  30. // CHECK:STDOUT: --- fail_error_recovery.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  34. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  35. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  36. // CHECK:STDOUT: %AddWith.type.e05: type = generic_interface_type @AddWith [concrete]
  37. // CHECK:STDOUT: %AddWith.generic: %AddWith.type.e05 = struct_value () [concrete]
  38. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  39. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  40. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  41. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  42. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  43. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  44. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: imports {
  48. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  49. // CHECK:STDOUT: .AddWith = %Core.AddWith
  50. // CHECK:STDOUT: .Int = %Core.Int
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core.AddWith: %AddWith.type.e05 = import_ref Core//prelude/operators/arithmetic, AddWith, loaded [concrete = constants.%AddWith.generic]
  55. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: file {
  59. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  60. // CHECK:STDOUT: .Core = imports.%Core
  61. // CHECK:STDOUT: .F = %F.decl
  62. // CHECK:STDOUT: .undeclared = <poisoned>
  63. // CHECK:STDOUT: .G = %G.decl
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %Core.import = import Core
  66. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  67. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  68. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = value_binding_pattern n [concrete]
  69. // CHECK:STDOUT: %n.param_patt: %pattern_type.7ce = value_param_pattern %n.patt, call_param0 [concrete]
  70. // CHECK:STDOUT: } {
  71. // CHECK:STDOUT: %n.param: %i32 = value_param call_param0
  72. // CHECK:STDOUT: %.loc26: type = splice_block %i32 [concrete = constants.%i32] {
  73. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  74. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %n: %i32 = value_binding n, %n.param
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @F() {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %undeclared.ref: <error> = name_ref undeclared, <error> [concrete = <error>]
  83. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  84. // CHECK:STDOUT: %impl.elem1: <error> = impl_witness_access <error>, element1 [concrete = <error>]
  85. // CHECK:STDOUT: return
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @G(%n.param: %i32) {
  89. // CHECK:STDOUT: !entry:
  90. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  91. // CHECK:STDOUT: %undeclared.ref: <error> = name_ref undeclared, <error> [concrete = <error>]
  92. // CHECK:STDOUT: return
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: