fail_params.carbon 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/namespace/fail_params.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/fail_params.carbon
  10. // CHECK:STDERR: fail_params.carbon:[[@LINE+4]]:12: ERROR: `namespace` declaration cannot have parameters.
  11. // CHECK:STDERR: namespace A();
  12. // CHECK:STDERR: ^~
  13. // CHECK:STDERR:
  14. namespace A();
  15. // Parameters are ignored for error recovery.
  16. fn A.F() {}
  17. // CHECK:STDERR: fail_params.carbon:[[@LINE+4]]:12: ERROR: `namespace` declaration cannot have parameters.
  18. // CHECK:STDERR: namespace B(n: i32);
  19. // CHECK:STDERR: ^~~~~~~~
  20. // CHECK:STDERR:
  21. namespace B(n: i32);
  22. // CHECK:STDERR: fail_params.carbon:[[@LINE+4]]:12: ERROR: `namespace` declaration cannot have parameters.
  23. // CHECK:STDERR: namespace C[T:! type](x: T);
  24. // CHECK:STDERR: ^~~~~~~~~~
  25. // CHECK:STDERR:
  26. namespace C[T:! type](x: T);
  27. namespace D;
  28. // CHECK:STDERR: fail_params.carbon:[[@LINE+6]]:4: ERROR: Redeclaration differs because of parameter list.
  29. // CHECK:STDERR: fn D(T:! type).F() {}
  30. // CHECK:STDERR: ^
  31. // CHECK:STDERR: fail_params.carbon:[[@LINE-4]]:1: Previously declared without parameter list.
  32. // CHECK:STDERR: namespace D;
  33. // CHECK:STDERR: ^~~~~~~~~~~~
  34. fn D(T:! type).F() {}
  35. // CHECK:STDOUT: --- fail_params.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  39. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  40. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  41. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  42. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  43. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  44. // CHECK:STDOUT: %.type: type = fn_type @.1 [template]
  45. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: imports {
  49. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  50. // CHECK:STDOUT: .Int32 = %import_ref
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/operators
  53. // CHECK:STDOUT: import Core//prelude/types
  54. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  55. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  56. // CHECK:STDOUT: import Core//prelude/operators/comparison
  57. // CHECK:STDOUT: import Core//prelude/types/bool
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .A = %A
  66. // CHECK:STDOUT: .B = %B
  67. // CHECK:STDOUT: .C = %C
  68. // CHECK:STDOUT: .D = %D
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %Core.import = import Core
  71. // CHECK:STDOUT: %A: <namespace> = namespace [template] {
  72. // CHECK:STDOUT: .F = %F.decl
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  75. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  76. // CHECK:STDOUT: %.loc24_16.1: type = value_of_initializer %int.make_type_32 [template = i32]
  77. // CHECK:STDOUT: %.loc24_16.2: type = converted %int.make_type_32, %.loc24_16.1 [template = i32]
  78. // CHECK:STDOUT: %n.loc24_13.1: i32 = param n
  79. // CHECK:STDOUT: %n.loc24_13.2: i32 = bind_name n, %n.loc24_13.1
  80. // CHECK:STDOUT: %B: <namespace> = namespace [template] {}
  81. // CHECK:STDOUT: %T.loc30_13.1: type = param T
  82. // CHECK:STDOUT: %T.loc30_13.2: type = bind_symbolic_name T 0, %T.loc30_13.1 [symbolic = constants.%T]
  83. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc30_13.2 [symbolic = constants.%T]
  84. // CHECK:STDOUT: %x.loc30_23.1: %T = param x
  85. // CHECK:STDOUT: %x.loc30_23.2: %T = bind_name x, %x.loc30_23.1
  86. // CHECK:STDOUT: %C: <namespace> = namespace [template] {}
  87. // CHECK:STDOUT: %D: <namespace> = namespace [template] {}
  88. // CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [template = constants.%.2] {
  89. // CHECK:STDOUT: %T.loc39_6.1: type = param T
  90. // CHECK:STDOUT: %T.loc39_6.2: type = bind_symbolic_name T 0, %T.loc39_6.1 [symbolic = @.1.%T (constants.%T)]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @F() {
  95. // CHECK:STDOUT: !entry:
  96. // CHECK:STDOUT: return
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: generic fn @.1(file.%T.loc39_6.2: type) {
  102. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: !definition:
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: fn() {
  107. // CHECK:STDOUT: !entry:
  108. // CHECK:STDOUT: return
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: specific @.1(constants.%T) {
  113. // CHECK:STDOUT: %T => constants.%T
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: