extern.carbon 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/function/declaration/no_prelude/extern.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/declaration/no_prelude/extern.carbon
  10. // --- basic.carbon
  11. library "basic";
  12. extern fn F();
  13. // --- fail_redecl.carbon
  14. library "redecl";
  15. extern fn F();
  16. // CHECK:STDERR: fail_redecl.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of `fn F` is redundant.
  17. // CHECK:STDERR: extern fn F();
  18. // CHECK:STDERR: ^~~~~~~~~~~~~~
  19. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: Previously declared here.
  20. // CHECK:STDERR: extern fn F();
  21. // CHECK:STDERR: ^~~~~~~~~~~~~~
  22. // CHECK:STDERR:
  23. extern fn F();
  24. // --- fail_redecl_extern.carbon
  25. library "redecl_extern";
  26. extern fn F();
  27. // CHECK:STDERR: fail_redecl_extern.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of `fn F` is redundant.
  28. // CHECK:STDERR: fn F();
  29. // CHECK:STDERR: ^~~~~~~
  30. // CHECK:STDERR: fail_redecl_extern.carbon:[[@LINE-4]]:1: Previously declared here.
  31. // CHECK:STDERR: extern fn F();
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~
  33. // CHECK:STDERR:
  34. fn F();
  35. // --- fail_member_extern.carbon
  36. class C {
  37. // CHECK:STDERR: fail_member_extern.carbon:[[@LINE+4]]:3: ERROR: `extern` not allowed on `fn` declaration that is a member.
  38. // CHECK:STDERR: extern fn F();
  39. // CHECK:STDERR: ^~~~~~
  40. // CHECK:STDERR:
  41. extern fn F();
  42. // CHECK:STDERR: fail_member_extern.carbon:[[@LINE+3]]:3: ERROR: `extern` not allowed on `fn` declaration that is a member.
  43. // CHECK:STDERR: extern fn G[self: Self]();
  44. // CHECK:STDERR: ^~~~~~
  45. extern fn G[self: Self]();
  46. }
  47. // CHECK:STDOUT: --- basic.carbon
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: constants {
  50. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  51. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  52. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .F = %F.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: extern fn @F();
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: --- fail_redecl.carbon
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: constants {
  67. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  68. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  69. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: file {
  73. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  74. // CHECK:STDOUT: .F = %F.decl.loc4
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %F.decl.loc4: %F.type = fn_decl @F [template = constants.%F] {}
  77. // CHECK:STDOUT: %F.decl.loc12: %F.type = fn_decl @F [template = constants.%F] {}
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: extern fn @F();
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: --- fail_redecl_extern.carbon
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: constants {
  85. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  86. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  87. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: file {
  91. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  92. // CHECK:STDOUT: .F = %F.decl.loc12
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %F.decl.loc4: %F.type = fn_decl @F [template = constants.%F] {}
  95. // CHECK:STDOUT: %F.decl.loc12: %F.type = fn_decl @F [template = constants.%F] {}
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @F();
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: --- fail_member_extern.carbon
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: constants {
  103. // CHECK:STDOUT: %C: type = class_type @C [template]
  104. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  105. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  106. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  107. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  108. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  109. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: file {
  113. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  114. // CHECK:STDOUT: .C = %C.decl
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: class @C {
  120. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  121. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  122. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  123. // CHECK:STDOUT: %self.loc11_15.1: %C = param self
  124. // CHECK:STDOUT: %self.loc11_15.2: %C = bind_name self, %self.loc11_15.1
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: !members:
  128. // CHECK:STDOUT: .Self = constants.%C
  129. // CHECK:STDOUT: .F = %F.decl
  130. // CHECK:STDOUT: .G = %G.decl
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: fn @F();
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: fn @G[@C.%self.loc11_15.2: %C]();
  136. // CHECK:STDOUT: