fail_member_of_let.carbon 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/class/fail_member_of_let.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_member_of_let.carbon
  10. class Class {
  11. fn F() -> i32;
  12. }
  13. // TODO: Use `:!` here once it is available.
  14. let T: type = Class;
  15. // The class name is required to be written in the same way as in the class
  16. // declaration. An expression that evaluates to the class name is not accepted.
  17. // CHECK:STDERR: fail_member_of_let.carbon:[[@LINE+6]]:4: error: name qualifiers are only allowed for entities that provide a scope
  18. // CHECK:STDERR: fn T.F() {}
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR: fail_member_of_let.carbon:[[@LINE-7]]:5: referenced non-scope entity declared here
  21. // CHECK:STDERR: let T: type = Class;
  22. // CHECK:STDERR: ^
  23. fn T.F() {}
  24. // CHECK:STDOUT: --- fail_member_of_let.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  28. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  29. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  30. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  31. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  32. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  33. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  34. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  35. // CHECK:STDOUT: %.type: type = fn_type @.1 [template]
  36. // CHECK:STDOUT: %.4: %.type = struct_value () [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: imports {
  40. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  41. // CHECK:STDOUT: .Int32 = %import_ref
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/operators
  44. // CHECK:STDOUT: import Core//prelude/types
  45. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  46. // CHECK:STDOUT: import Core//prelude/operators/as
  47. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  48. // CHECK:STDOUT: import Core//prelude/operators/comparison
  49. // CHECK:STDOUT: import Core//prelude/types/bool
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  56. // CHECK:STDOUT: .Core = imports.%Core
  57. // CHECK:STDOUT: .Class = %Class.decl
  58. // CHECK:STDOUT: .T = @__global_init.%T
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Core.import = import Core
  61. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  62. // CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [template = constants.%.4] {}
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: class @Class {
  66. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  67. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  68. // CHECK:STDOUT: %.loc12_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  69. // CHECK:STDOUT: %.loc12_13.2: type = converted %int.make_type_32, %.loc12_13.1 [template = i32]
  70. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %.loc13: <witness> = complete_type_witness %.2 [template = constants.%.3]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = constants.%Class
  76. // CHECK:STDOUT: .F = %F.decl
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @F() -> i32;
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @.1() {
  84. // CHECK:STDOUT: !entry:
  85. // CHECK:STDOUT: return
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @__global_init() {
  89. // CHECK:STDOUT: !entry:
  90. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  91. // CHECK:STDOUT: %T: type = bind_name T, %Class.ref
  92. // CHECK:STDOUT: return
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: