builtins.carbon 4.2 KB

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