fail_error_recovery.carbon 4.7 KB

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