fail_not_constant.carbon 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/no_prelude/fail_not_constant.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/no_prelude/fail_not_constant.carbon
  10. fn F() {
  11. var a: () = ();
  12. var b: ()* = &a;
  13. // CHECK:STDERR: fail_not_constant.carbon:[[@LINE+3]]:13: error: alias initializer must be a name reference [AliasRequiresNameRef]
  14. // CHECK:STDERR: alias c = *b;
  15. // CHECK:STDERR: ^~
  16. alias c = *b;
  17. }
  18. // CHECK:STDOUT: --- fail_not_constant.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  22. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  23. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  24. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [template]
  25. // CHECK:STDOUT: %ptr: type = ptr_type %empty_tuple.type [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: file {
  29. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  30. // CHECK:STDOUT: .F = %F.decl
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: fn @F() {
  36. // CHECK:STDOUT: !entry:
  37. // CHECK:STDOUT: %a.var: ref %empty_tuple.type = var a
  38. // CHECK:STDOUT: %a: ref %empty_tuple.type = bind_name a, %a.var
  39. // CHECK:STDOUT: %.loc12_16.1: %empty_tuple.type = tuple_literal ()
  40. // CHECK:STDOUT: %.loc12_16.2: init %empty_tuple.type = tuple_init () to %a.var [template = constants.%empty_tuple]
  41. // CHECK:STDOUT: %.loc12_17: init %empty_tuple.type = converted %.loc12_16.1, %.loc12_16.2 [template = constants.%empty_tuple]
  42. // CHECK:STDOUT: assign %a.var, %.loc12_17
  43. // CHECK:STDOUT: %b.var: ref %ptr = var b
  44. // CHECK:STDOUT: %b: ref %ptr = bind_name b, %b.var
  45. // CHECK:STDOUT: %a.ref: ref %empty_tuple.type = name_ref a, %a
  46. // CHECK:STDOUT: %addr: %ptr = addr_of %a.ref
  47. // CHECK:STDOUT: assign %b.var, %addr
  48. // CHECK:STDOUT: %b.ref: ref %ptr = name_ref b, %b
  49. // CHECK:STDOUT: %.loc17_14: %ptr = bind_value %b.ref
  50. // CHECK:STDOUT: %.loc17_13: ref %empty_tuple.type = deref %.loc17_14
  51. // CHECK:STDOUT: %c: <error> = bind_alias c, <error> [template = <error>]
  52. // CHECK:STDOUT: return
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: