comp_time_field.carbon 4.5 KB

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