fail_collapse.carbon 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/const/fail_collapse.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/const/fail_collapse.carbon
  10. // CHECK:STDERR: fail_collapse.carbon:[[@LINE+4]]:9: warning: `const` applied repeatedly to the same type has no additional effect [RepeatedConst]
  11. // CHECK:STDERR: fn G(p: const (const i32)**) -> i32** {
  12. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  13. // CHECK:STDERR:
  14. fn G(p: const (const i32)**) -> i32** {
  15. // CHECK:STDERR: fail_collapse.carbon:[[@LINE+6]]:3: error: cannot implicitly convert from `const i32**` to `i32**` [ImplicitAsConversionFailure]
  16. // CHECK:STDERR: return p;
  17. // CHECK:STDERR: ^~~~~~~~~
  18. // CHECK:STDERR: fail_collapse.carbon:[[@LINE+3]]:3: note: type `const i32**` does not implement interface `ImplicitAs(i32**)` [MissingImplInMemberAccessNote]
  19. // CHECK:STDERR: return p;
  20. // CHECK:STDERR: ^~~~~~~~~
  21. return p;
  22. }
  23. // CHECK:STDOUT: --- fail_collapse.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  27. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  28. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  29. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  30. // CHECK:STDOUT: %.2: type = const_type %i32 [template]
  31. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  32. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  33. // CHECK:STDOUT: %.5: type = ptr_type %i32 [template]
  34. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  35. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  36. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: imports {
  40. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  41. // CHECK:STDOUT: .Int = %import_ref.1
  42. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  43. // CHECK:STDOUT: import Core//prelude
  44. // CHECK:STDOUT: import Core//prelude/...
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = imports.%Core
  51. // CHECK:STDOUT: .G = %G.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  55. // CHECK:STDOUT: %p.patt: %.4 = binding_pattern p
  56. // CHECK:STDOUT: %p.param_patt: %.4 = value_param_pattern %p.patt, runtime_param0
  57. // CHECK:STDOUT: %return.patt: %.6 = return_slot_pattern
  58. // CHECK:STDOUT: %return.param_patt: %.6 = out_param_pattern %return.patt, runtime_param1
  59. // CHECK:STDOUT: } {
  60. // CHECK:STDOUT: %.loc15_22: Core.IntLiteral = int_value 32 [template = constants.%.1]
  61. // CHECK:STDOUT: %int.make_type_signed.loc15_22: init type = call constants.%Int(%.loc15_22) [template = constants.%i32]
  62. // CHECK:STDOUT: %.loc15_16.1: type = value_of_initializer %int.make_type_signed.loc15_22 [template = constants.%i32]
  63. // CHECK:STDOUT: %.loc15_16.2: type = converted %int.make_type_signed.loc15_22, %.loc15_16.1 [template = constants.%i32]
  64. // CHECK:STDOUT: %.loc15_16.3: type = const_type %i32 [template = constants.%.2]
  65. // CHECK:STDOUT: %.loc15_9: type = const_type %.2 [template = constants.%.2]
  66. // CHECK:STDOUT: %.loc15_26: type = ptr_type %.2 [template = constants.%.3]
  67. // CHECK:STDOUT: %.loc15_27: type = ptr_type %.3 [template = constants.%.4]
  68. // CHECK:STDOUT: %.loc15_33: Core.IntLiteral = int_value 32 [template = constants.%.1]
  69. // CHECK:STDOUT: %int.make_type_signed.loc15_33: init type = call constants.%Int(%.loc15_33) [template = constants.%i32]
  70. // CHECK:STDOUT: %.loc15_36.1: type = value_of_initializer %int.make_type_signed.loc15_33 [template = constants.%i32]
  71. // CHECK:STDOUT: %.loc15_36.2: type = converted %int.make_type_signed.loc15_33, %.loc15_36.1 [template = constants.%i32]
  72. // CHECK:STDOUT: %.loc15_36.3: type = ptr_type %i32 [template = constants.%.5]
  73. // CHECK:STDOUT: %.loc15_37: type = ptr_type %.5 [template = constants.%.6]
  74. // CHECK:STDOUT: %p.param: %.4 = value_param runtime_param0
  75. // CHECK:STDOUT: %p: %.4 = bind_name p, %p.param
  76. // CHECK:STDOUT: %return.param: ref %.6 = out_param runtime_param1
  77. // CHECK:STDOUT: %return: ref %.6 = return_slot %return.param
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @G(%p.param_patt: %.4) -> %.6 {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: %p.ref: %.4 = name_ref p, %p
  84. // CHECK:STDOUT: %.loc22: %.6 = converted %p.ref, <error> [template = <error>]
  85. // CHECK:STDOUT: return <error>
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: