fail_generic.carbon 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 expression of type `Core.IntLiteral` to `T` [ConversionFailure]
  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 expression of type `T` to `i32` [ConversionFailure]
  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 [concrete]
  34. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  35. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  36. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  37. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  38. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  39. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  40. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  41. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  42. // CHECK:STDOUT: %pattern_type.7dcd0a.1: type = pattern_type %T [symbolic]
  43. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [concrete]
  44. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  45. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  46. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
  47. // CHECK:STDOUT: %Convert.type.2751f3.1: type = fn_type @Convert.1, @ImplicitAs(%Dest) [symbolic]
  48. // CHECK:STDOUT: %Convert.42ebb8.1: %Convert.type.2751f3.1 = struct_value () [symbolic]
  49. // CHECK:STDOUT: %ImplicitAs.assoc_type.ca0d85.1: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  50. // CHECK:STDOUT: %ImplicitAs.type.d628ce.2: type = facet_type <@ImplicitAs, @ImplicitAs(%T)> [symbolic]
  51. // CHECK:STDOUT: %ImplicitAs.assoc_type.ca0d85.2: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%T) [symbolic]
  52. // CHECK:STDOUT: %assoc0.9f5e6b.2: %ImplicitAs.assoc_type.ca0d85.2 = assoc_entity element0, imports.%Core.import_ref.1c7 [symbolic]
  53. // CHECK:STDOUT: %assoc0.dc0: %ImplicitAs.assoc_type.ca0d85.1 = assoc_entity element0, imports.%Core.import_ref.207 [symbolic]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: imports {
  57. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  58. // CHECK:STDOUT: .Int = %Core.Int
  59. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  60. // CHECK:STDOUT: import Core//prelude
  61. // CHECK:STDOUT: import Core//prelude/...
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  64. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  65. // CHECK:STDOUT: %Core.import_ref.492: @ImplicitAs.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.ca0d85.1) = import_ref Core//prelude/operators/as, loc13_35, loaded [symbolic = @ImplicitAs.%assoc0 (constants.%assoc0.dc0)]
  66. // CHECK:STDOUT: %Core.import_ref.1c7: @ImplicitAs.%Convert.type (%Convert.type.2751f3.1) = import_ref Core//prelude/operators/as, loc13_35, loaded [symbolic = @ImplicitAs.%Convert (constants.%Convert.42ebb8.1)]
  67. // CHECK:STDOUT: %Core.import_ref.207 = import_ref Core//prelude/operators/as, loc13_35, unloaded
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: file {
  71. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  72. // CHECK:STDOUT: .Core = imports.%Core
  73. // CHECK:STDOUT: .F = %F.decl
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %Core.import = import Core
  76. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  77. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a [concrete]
  78. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  79. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  80. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  81. // CHECK:STDOUT: } {
  82. // CHECK:STDOUT: %int_32.loc12_17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  83. // CHECK:STDOUT: %i32.loc12_17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  84. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  85. // CHECK:STDOUT: %.loc12: type = splice_block %i32.loc12_9 [concrete = constants.%i32] {
  86. // CHECK:STDOUT: %int_32.loc12_9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  87. // CHECK:STDOUT: %i32.loc12_9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  90. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  91. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn @F(%a.param: %i32) -> %i32 {
  96. // CHECK:STDOUT: !entry:
  97. // CHECK:STDOUT: name_binding_decl {
  98. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: %int_32.loc13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  101. // CHECK:STDOUT: %i32.loc13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  102. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, %i32.loc13 [symbolic = constants.%T]
  103. // CHECK:STDOUT: name_binding_decl {
  104. // CHECK:STDOUT: %x.patt: %pattern_type.7dcd0a.1 = binding_pattern x [concrete]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [concrete = constants.%int_5]
  107. // CHECK:STDOUT: %T.ref: type = name_ref T, %T [symbolic = constants.%T]
  108. // CHECK:STDOUT: %ImplicitAs.type: type = facet_type <@ImplicitAs, @ImplicitAs(constants.%T)> [symbolic = constants.%ImplicitAs.type.d628ce.2]
  109. // CHECK:STDOUT: %.loc21_14.1: %ImplicitAs.assoc_type.ca0d85.2 = specific_constant imports.%Core.import_ref.492, @ImplicitAs(constants.%T) [symbolic = constants.%assoc0.9f5e6b.2]
  110. // CHECK:STDOUT: %Convert.ref: %ImplicitAs.assoc_type.ca0d85.2 = name_ref Convert, %.loc21_14.1 [symbolic = constants.%assoc0.9f5e6b.2]
  111. // CHECK:STDOUT: %.loc21_14.2: %T = converted %int_5, <error> [concrete = <error>]
  112. // CHECK:STDOUT: %x: %T = bind_name x, <error>
  113. // CHECK:STDOUT: %x.ref: %T = name_ref x, %x
  114. // CHECK:STDOUT: %.loc29: %i32 = converted %x.ref, <error> [concrete = <error>]
  115. // CHECK:STDOUT: return <error>
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: