fail_generic.carbon 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/let/fail_generic.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/fail_generic.carbon
  10. // TODO: Should this be valid?
  11. fn F(a: i32) -> i32 {
  12. let T:! type = i32;
  13. // CHECK:STDERR: fail_generic.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `Core.IntLiteral` to `T` [ImplicitAsConversionFailure]
  14. // CHECK:STDERR: let x: T = 5;
  15. // CHECK:STDERR: ^~~~~~~~~~~~~
  16. // CHECK:STDERR: fail_generic.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(T)` [MissingImplInMemberAccessNote]
  17. // CHECK:STDERR: let x: T = 5;
  18. // CHECK:STDERR: ^~~~~~~~~~~~~
  19. // CHECK:STDERR:
  20. let x: T = 5;
  21. // CHECK:STDERR: fail_generic.carbon:[[@LINE+6]]:3: error: cannot implicitly convert from `T` to `i32` [ImplicitAsConversionFailure]
  22. // CHECK:STDERR: return x;
  23. // CHECK:STDERR: ^~~~~~~~~
  24. // CHECK:STDERR: fail_generic.carbon:[[@LINE+3]]:3: note: type `T` does not implement interface `Core.ImplicitAs(i32)` [MissingImplInMemberAccessNote]
  25. // CHECK:STDERR: return x;
  26. // CHECK:STDERR: ^~~~~~~~~
  27. return x;
  28. }
  29. // CHECK:STDOUT: --- fail_generic.carbon
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: constants {
  32. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  33. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  34. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  35. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  36. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  37. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [template]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: imports {
  41. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  42. // CHECK:STDOUT: .Int = %import_ref.1
  43. // CHECK:STDOUT: .ImplicitAs = %import_ref.5
  44. // CHECK:STDOUT: import Core//prelude
  45. // CHECK:STDOUT: import Core//prelude/...
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: file {
  50. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  51. // CHECK:STDOUT: .Core = imports.%Core
  52. // CHECK:STDOUT: .F = %F.decl
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core.import = import Core
  55. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  56. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  57. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  58. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  59. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  60. // CHECK:STDOUT: } {
  61. // CHECK:STDOUT: %int_32.loc12_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  62. // CHECK:STDOUT: %i32.loc12_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  63. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  64. // CHECK:STDOUT: %.loc12: type = splice_block %i32.loc12_9 [template = constants.%i32] {
  65. // CHECK:STDOUT: %int_32.loc12_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  66. // CHECK:STDOUT: %i32.loc12_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  69. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  70. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @F(%a.param_patt: %i32) -> %i32 {
  75. // CHECK:STDOUT: !entry:
  76. // CHECK:STDOUT: %int_32.loc13: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  77. // CHECK:STDOUT: %i32.loc13: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  78. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, %i32.loc13 [symbolic = constants.%T]
  79. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [template = constants.%int_5]
  80. // CHECK:STDOUT: %.loc21: %T = converted %int_5, <error> [template = <error>]
  81. // CHECK:STDOUT: %x: %T = bind_name x, <error>
  82. // CHECK:STDOUT: %x.ref: %T = name_ref x, %x
  83. // CHECK:STDOUT: %.loc28: %i32 = converted %x.ref, <error> [template = <error>]
  84. // CHECK:STDOUT: return <error>
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: