builtins.carbon 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/alias/builtins.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/builtins.carbon
  10. // --- fail_i32.carbon
  11. library "[[@TEST_NAME]]";
  12. //@dump-sem-ir-begin
  13. // CHECK:STDERR: fail_i32.carbon:[[@LINE+4]]:11: error: alias initializer must be a name reference [AliasRequiresNameRef]
  14. // CHECK:STDERR: alias a = i32;
  15. // CHECK:STDERR: ^~~
  16. // CHECK:STDERR:
  17. alias a = i32;
  18. //@dump-sem-ir-end
  19. // --- fail_bool.carbon
  20. library "[[@TEST_NAME]]";
  21. //@dump-sem-ir-begin
  22. // CHECK:STDERR: fail_bool.carbon:[[@LINE+4]]:11: error: alias initializer must be a name reference [AliasRequiresNameRef]
  23. // CHECK:STDERR: alias b = bool;
  24. // CHECK:STDERR: ^~~~
  25. // CHECK:STDERR:
  26. alias b = bool;
  27. //@dump-sem-ir-end
  28. // --- fail_bool_value.carbon
  29. library "[[@TEST_NAME]]";
  30. //@dump-sem-ir-begin
  31. // CHECK:STDERR: fail_bool_value.carbon:[[@LINE+4]]:11: error: alias initializer must be a name reference [AliasRequiresNameRef]
  32. // CHECK:STDERR: alias a = false;
  33. // CHECK:STDERR: ^~~~~
  34. // CHECK:STDERR:
  35. alias a = false;
  36. // This fails silently due to the above diagnostic.
  37. let a_test: bool = a;
  38. //@dump-sem-ir-end
  39. // CHECK:STDOUT: --- fail_i32.carbon
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: constants {
  42. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  43. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: file {
  50. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  51. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  52. // CHECK:STDOUT: %a: <error> = bind_alias a, <error> [concrete = <error>]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: --- fail_bool.carbon
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: constants {
  58. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  59. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: imports {
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  67. // CHECK:STDOUT: %b: <error> = bind_alias b, <error> [concrete = <error>]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: --- fail_bool_value.carbon
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: constants {
  73. // CHECK:STDOUT: %false: bool = bool_literal false [concrete]
  74. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  75. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  76. // CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: imports {
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: file {
  83. // CHECK:STDOUT: %false: bool = bool_literal false [concrete = constants.%false]
  84. // CHECK:STDOUT: %a: <error> = bind_alias a, <error> [concrete = <error>]
  85. // CHECK:STDOUT: name_binding_decl {
  86. // CHECK:STDOUT: %a_test.patt: %pattern_type.831 = binding_pattern a_test [concrete]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %.loc12_13.1: type = splice_block %.loc12_13.3 [concrete = bool] {
  89. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  90. // CHECK:STDOUT: %.loc12_13.2: type = value_of_initializer %bool.make_type [concrete = bool]
  91. // CHECK:STDOUT: %.loc12_13.3: type = converted %bool.make_type, %.loc12_13.2 [concrete = bool]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %a_test: bool = bind_name a_test, <error> [concrete = <error>]
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @__global_init() {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: %a.ref: <error> = name_ref a, file.%a [concrete = <error>]
  99. // CHECK:STDOUT: <elided>
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: