init_dependent_bound.carbon 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/array/init_dependent_bound.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/init_dependent_bound.carbon
  10. // --- fail_init_dependent_bound.carbon
  11. library "[[@TEST_NAME]]";
  12. fn F(N:! i32) {
  13. // CHECK:STDERR: fail_init_dependent_bound.carbon:[[@LINE+4]]:23: error: cannot initialize array with dependent bound from a list of initializers [ArrayInitDependentBound]
  14. // CHECK:STDERR: var arr: [i32; N] = (1, 2, 3);
  15. // CHECK:STDERR: ^~~~~~~~~
  16. // CHECK:STDERR:
  17. var arr: [i32; N] = (1, 2, 3);
  18. }
  19. // --- fail_todo_init_template_dependent_bound.carbon
  20. library "[[@TEST_NAME]]";
  21. // TODO: This should be valid.
  22. // CHECK:STDERR: fail_todo_init_template_dependent_bound.carbon:[[@LINE+3]]:6: error: semantics TODO: `HandleTemplate` [SemanticsTodo]
  23. // CHECK:STDERR: fn G(template N:! i32) {
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  25. fn G(template N:! i32) {
  26. var arr: [i32; N] = (1, 2, 3);
  27. }
  28. fn H() { G(3); }
  29. // CHECK:STDOUT: --- fail_init_dependent_bound.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: %N.51e: %i32 = bind_symbolic_name N, 0 [symbolic]
  35. // CHECK:STDOUT: %N.patt.8e2: %i32 = symbolic_binding_pattern N, 0 [symbolic]
  36. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  37. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  38. // CHECK:STDOUT: %Convert.type.4ad: type = fn_type @Convert.3, @impl.2(%int_32) [template]
  39. // CHECK:STDOUT: %Convert.960: %Convert.type.4ad = struct_value () [template]
  40. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %N.51e, %Convert.960 [symbolic]
  41. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.3(%int_32) [symbolic]
  42. // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %Convert.specific_fn(%N.51e) [symbolic]
  43. // CHECK:STDOUT: %array_type: type = array_type %int.convert_checked, %i32 [symbolic]
  44. // CHECK:STDOUT: %require_complete.9dc: <witness> = require_complete_type %array_type [symbolic]
  45. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  46. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template]
  47. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template]
  48. // CHECK:STDOUT: %tuple.type: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [template]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: imports {
  52. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  53. // CHECK:STDOUT: .Int = %import_ref.485
  54. // CHECK:STDOUT: .ImplicitAs = %import_ref.d44
  55. // CHECK:STDOUT: import Core//prelude
  56. // CHECK:STDOUT: import Core//prelude/...
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: file {
  61. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  62. // CHECK:STDOUT: .Core = imports.%Core
  63. // CHECK:STDOUT: .F = %F.decl
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %Core.import = import Core
  66. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  67. // CHECK:STDOUT: %N.patt.loc4_6.1: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_6.2 (constants.%N.patt.8e2)]
  68. // CHECK:STDOUT: %N.param_patt: %i32 = value_param_pattern %N.patt.loc4_6.1, runtime_param<invalid> [symbolic = %N.patt.loc4_6.2 (constants.%N.patt.8e2)]
  69. // CHECK:STDOUT: } {
  70. // CHECK:STDOUT: %N.param: %i32 = value_param runtime_param<invalid>
  71. // CHECK:STDOUT: %.loc4: type = splice_block %i32 [template = constants.%i32] {
  72. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  73. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %N.loc4_6.1: %i32 = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc4_6.2 (constants.%N.51e)]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: generic fn @F(%N.loc4_6.1: %i32) {
  80. // CHECK:STDOUT: %N.loc4_6.2: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc4_6.2 (constants.%N.51e)]
  81. // CHECK:STDOUT: %N.patt.loc4_6.2: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_6.2 (constants.%N.patt.8e2)]
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !definition:
  84. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %N.loc4_6.2, constants.%Convert.960 [symbolic = %Convert.bound (constants.%Convert.bound)]
  85. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.3(constants.%int_32) [symbolic = %Convert.specific_fn (constants.%Convert.specific_fn)]
  86. // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %Convert.specific_fn(%N.loc4_6.2) [symbolic = %int.convert_checked (constants.%int.convert_checked)]
  87. // CHECK:STDOUT: %array_type: type = array_type %int.convert_checked, %i32 [symbolic = %array_type (constants.%array_type)]
  88. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type @F.%array_type (%array_type) [symbolic = %require_complete (constants.%require_complete.9dc)]
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn(%N.param_patt: %i32) {
  91. // CHECK:STDOUT: !entry:
  92. // CHECK:STDOUT: %arr.var: ref @F.%array_type (%array_type) = var arr
  93. // CHECK:STDOUT: %arr: ref @F.%array_type (%array_type) = bind_name arr, %arr.var
  94. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  95. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2]
  96. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template = constants.%int_3]
  97. // CHECK:STDOUT: %.loc9: %tuple.type = tuple_literal (%int_1, %int_2, %int_3)
  98. // CHECK:STDOUT: assign %arr.var, <error>
  99. // CHECK:STDOUT: return
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: specific @F(constants.%N.51e) {
  104. // CHECK:STDOUT: %N.loc4_6.2 => constants.%N.51e
  105. // CHECK:STDOUT: %N.patt.loc4_6.2 => constants.%N.51e
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: --- fail_todo_init_template_dependent_bound.carbon
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: constants {
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: file {}
  114. // CHECK:STDOUT: