comp_time_field.carbon 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --no-prelude-import --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/comp_time_field.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/comp_time_field.carbon
  13. // --- fail_let.carbon
  14. library "[[@TEST_NAME]]";
  15. class Class {
  16. // CHECK:STDERR: fail_let.carbon:[[@LINE+4]]:7: error: semantics TODO: ``let` compile time binding outside function or interface` [SemanticsTodo]
  17. // CHECK:STDERR: let A:! type = Class;
  18. // CHECK:STDERR: ^~~~~~~~
  19. // CHECK:STDERR:
  20. let A:! type = Class;
  21. // CHECK:STDERR: fail_let.carbon:[[@LINE+4]]:7: error: semantics TODO: ``let` compile time binding outside function or interface` [SemanticsTodo]
  22. // CHECK:STDERR: let template B:! type = Class;
  23. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  24. // CHECK:STDERR:
  25. let template B:! type = Class;
  26. }
  27. // --- fail_var.carbon
  28. library "[[@TEST_NAME]]";
  29. class Class {
  30. // CHECK:STDERR: fail_var.carbon:[[@LINE+8]]:8: error: expected `:` in field declaration [ExpectedFieldColon]
  31. // CHECK:STDERR: var C:! type = Class;
  32. // CHECK:STDERR: ^~
  33. // CHECK:STDERR:
  34. // CHECK:STDERR: fail_var.carbon:[[@LINE+4]]:3: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  35. // CHECK:STDERR: var C:! type = Class;
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. var C:! type = Class;
  39. // CHECK:STDERR: fail_var.carbon:[[@LINE+4]]:7: error: expected identifier in field declaration [ExpectedFieldIdentifier]
  40. // CHECK:STDERR: var template D:! type = Class;
  41. // CHECK:STDERR: ^~~~~~~~
  42. // CHECK:STDERR:
  43. var template D:! type = Class;
  44. }
  45. var x: Class = {};
  46. // CHECK:STDOUT: --- fail_let.carbon
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: constants {
  49. // CHECK:STDOUT: %Class: type = class_type @Class [concrete]
  50. // CHECK:STDOUT: %pattern_type: type = pattern_type type [concrete]
  51. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  52. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  57. // CHECK:STDOUT: .Class = %Class.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [concrete = constants.%Class] {} {}
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: class @Class {
  63. // CHECK:STDOUT: name_binding_decl {
  64. // CHECK:STDOUT: %A.patt: %pattern_type = binding_pattern A [concrete]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %Class.ref.loc9: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  67. // CHECK:STDOUT: %A: type = bind_name A, %Class.ref.loc9
  68. // CHECK:STDOUT: name_binding_decl {
  69. // CHECK:STDOUT: %B.patt: %pattern_type = binding_pattern B [concrete]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Class.ref.loc15: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  72. // CHECK:STDOUT: %B: type = bind_name B, %Class.ref.loc15
  73. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  74. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  75. // CHECK:STDOUT: complete_type_witness = %complete_type
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !members:
  78. // CHECK:STDOUT: .Self = constants.%Class
  79. // CHECK:STDOUT: .A = %A
  80. // CHECK:STDOUT: .Class = <poisoned>
  81. // CHECK:STDOUT: .B = %B
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: --- fail_var.carbon
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: constants {
  87. // CHECK:STDOUT: %Class: type = class_type @Class [concrete]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: class @Class {
  91. // CHECK:STDOUT: complete_type_witness = invalid
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: !members:
  94. // CHECK:STDOUT: .Self = constants.%Class
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: