fail_generic.carbon 5.0 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/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]]:14: 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]]:14: 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+7]]: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+4]]:3: note: type `T` does not implement interface `Core.ImplicitAs(i32)` [MissingImplInMemberAccessNote]
  25. // CHECK:STDERR: return x;
  26. // CHECK:STDERR: ^~~~~~~~~
  27. // CHECK:STDERR:
  28. return x;
  29. }
  30. // CHECK:STDOUT: --- fail_generic.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  34. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  35. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  36. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  37. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  38. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  39. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [template]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  44. // CHECK:STDOUT: .Int = %Core.Int
  45. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  53. // CHECK:STDOUT: .Core = imports.%Core
  54. // CHECK:STDOUT: .F = %F.decl
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.import = import Core
  57. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  58. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  59. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  60. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  61. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  62. // CHECK:STDOUT: } {
  63. // CHECK:STDOUT: %int_32.loc12_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  64. // CHECK:STDOUT: %i32.loc12_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  65. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  66. // CHECK:STDOUT: %.loc12: type = splice_block %i32.loc12_9 [template = constants.%i32] {
  67. // CHECK:STDOUT: %int_32.loc12_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  68. // CHECK:STDOUT: %i32.loc12_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  71. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  72. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @F(%a.param_patt: %i32) -> %i32 {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: name_binding_decl {
  79. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic = constants.%T.patt]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %int_32.loc13: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  82. // CHECK:STDOUT: %i32.loc13: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  83. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, %i32.loc13 [symbolic = constants.%T]
  84. // CHECK:STDOUT: name_binding_decl {
  85. // CHECK:STDOUT: %x.patt: %T = binding_pattern x
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [template = constants.%int_5]
  88. // CHECK:STDOUT: %T.ref: type = name_ref T, %T [symbolic = constants.%T]
  89. // CHECK:STDOUT: %.loc21: %T = converted %int_5, <error> [template = <error>]
  90. // CHECK:STDOUT: %x: %T = bind_name x, <error>
  91. // CHECK:STDOUT: %x.ref: %T = name_ref x, %x
  92. // CHECK:STDOUT: %.loc29: %i32 = converted %x.ref, <error> [template = <error>]
  93. // CHECK:STDOUT: return <error>
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: