fail_generic.carbon 5.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 `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 `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: %.1: Core.IntLiteral = int_value 32 [template]
  33. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  34. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  35. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  36. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  37. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  38. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  39. // CHECK:STDOUT: %.2: 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 = %import_ref.1
  45. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  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: %.loc12_9.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  64. // CHECK:STDOUT: %int.make_type_signed.loc12_9: init type = call constants.%Int(%.loc12_9.1) [template = constants.%i32]
  65. // CHECK:STDOUT: %.loc12_9.2: type = value_of_initializer %int.make_type_signed.loc12_9 [template = constants.%i32]
  66. // CHECK:STDOUT: %.loc12_9.3: type = converted %int.make_type_signed.loc12_9, %.loc12_9.2 [template = constants.%i32]
  67. // CHECK:STDOUT: %.loc12_17.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  68. // CHECK:STDOUT: %int.make_type_signed.loc12_17: init type = call constants.%Int(%.loc12_17.1) [template = constants.%i32]
  69. // CHECK:STDOUT: %.loc12_17.2: type = value_of_initializer %int.make_type_signed.loc12_17 [template = constants.%i32]
  70. // CHECK:STDOUT: %.loc12_17.3: type = converted %int.make_type_signed.loc12_17, %.loc12_17.2 [template = constants.%i32]
  71. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  72. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  73. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  74. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @F(%a.param_patt: %i32) -> %i32 {
  79. // CHECK:STDOUT: !entry:
  80. // CHECK:STDOUT: %.loc13_18: Core.IntLiteral = int_value 32 [template = constants.%.1]
  81. // CHECK:STDOUT: %int.make_type_signed.loc13: init type = call constants.%Int(%.loc13_18) [template = constants.%i32]
  82. // CHECK:STDOUT: %.loc13_21.1: type = value_of_initializer %int.make_type_signed.loc13 [template = constants.%i32]
  83. // CHECK:STDOUT: %.loc13_21.2: type = converted %int.make_type_signed.loc13, %.loc13_21.1 [template = constants.%i32]
  84. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, %.loc13_21.2 [symbolic = constants.%T]
  85. // CHECK:STDOUT: %T.ref: type = name_ref T, %T [symbolic = constants.%T]
  86. // CHECK:STDOUT: %.loc21_14: Core.IntLiteral = int_value 5 [template = constants.%.2]
  87. // CHECK:STDOUT: %.loc21_15: %T = converted %.loc21_14, <error> [template = <error>]
  88. // CHECK:STDOUT: %x: %T = bind_name x, <error>
  89. // CHECK:STDOUT: %x.ref: %T = name_ref x, %x
  90. // CHECK:STDOUT: %.loc28: %i32 = converted %x.ref, <error> [template = <error>]
  91. // CHECK:STDOUT: return <error>
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: