fail_error_recovery.carbon 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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: %Int.type: type = generic_class_type @Int [concrete]
  36. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  37. // CHECK:STDOUT: %N: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic]
  38. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  39. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  40. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  41. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  42. // CHECK:STDOUT: %Op.type.52d: type = fn_type @Op.2, @impl.2c2(%N) [symbolic]
  43. // CHECK:STDOUT: %Op.12d: %Op.type.52d = struct_value () [symbolic]
  44. // CHECK:STDOUT: %Add.impl_witness.dbc: <witness> = impl_witness imports.%Add.impl_witness_table, @impl.2c2(%int_32) [concrete]
  45. // CHECK:STDOUT: %Op.type.210: type = fn_type @Op.2, @impl.2c2(%int_32) [concrete]
  46. // CHECK:STDOUT: %Op.c82: %Op.type.210 = struct_value () [concrete]
  47. // CHECK:STDOUT: %Add.facet: %Add.type = facet_value %i32, (%Add.impl_witness.dbc) [concrete]
  48. // CHECK:STDOUT: %.ac9: type = fn_type_with_self_type %Op.type.545, %Add.facet [concrete]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: imports {
  52. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  53. // CHECK:STDOUT: .Add = %Core.Add
  54. // CHECK:STDOUT: .Int = %Core.Int
  55. // CHECK:STDOUT: import Core//prelude
  56. // CHECK:STDOUT: import Core//prelude/...
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.Add: type = import_ref Core//prelude/operators/arithmetic, Add, loaded [concrete = constants.%Add.type]
  59. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  60. // CHECK:STDOUT: %Core.import_ref.344: @impl.2c2.%Op.type (%Op.type.52d) = import_ref Core//prelude/types/int, loc58_42, loaded [symbolic = @impl.2c2.%Op (constants.%Op.12d)]
  61. // CHECK:STDOUT: %Add.impl_witness_table = impl_witness_table (%Core.import_ref.344), @impl.2c2 [concrete]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: file {
  65. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  66. // CHECK:STDOUT: .Core = imports.%Core
  67. // CHECK:STDOUT: .F = %F.decl
  68. // CHECK:STDOUT: .undeclared = <poisoned>
  69. // CHECK:STDOUT: .G = %G.decl
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core.import = import Core
  72. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  73. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  74. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = binding_pattern n [concrete]
  75. // CHECK:STDOUT: %n.param_patt: %pattern_type.7ce = value_param_pattern %n.patt, call_param0 [concrete]
  76. // CHECK:STDOUT: } {
  77. // CHECK:STDOUT: %n.param: %i32 = value_param call_param0
  78. // CHECK:STDOUT: %.loc22: type = splice_block %i32 [concrete = constants.%i32] {
  79. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  80. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn @F() {
  87. // CHECK:STDOUT: !entry:
  88. // CHECK:STDOUT: %undeclared.ref: <error> = name_ref undeclared, <error> [concrete = <error>]
  89. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  90. // CHECK:STDOUT: %impl.elem0: <error> = impl_witness_access <error>, element0 [concrete = <error>]
  91. // CHECK:STDOUT: return
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @G(%n.param: %i32) {
  95. // CHECK:STDOUT: !entry:
  96. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  97. // CHECK:STDOUT: %undeclared.ref: <error> = name_ref undeclared, <error> [concrete = <error>]
  98. // CHECK:STDOUT: %impl.elem0: %.ac9 = impl_witness_access constants.%Add.impl_witness.dbc, element0 [concrete = constants.%Op.c82]
  99. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %n.ref, %impl.elem0
  100. // CHECK:STDOUT: return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: