fail_not_callable.carbon 5.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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: --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/function/call/fail_not_callable.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/fail_not_callable.carbon
  13. fn Run() {
  14. // CHECK:STDERR: fail_not_callable.carbon:[[@LINE+4]]:16: error: value of type `String` is not callable [CallToNonCallable]
  15. // CHECK:STDERR: var x: i32 = "hello"();
  16. // CHECK:STDERR: ^~~~~~~~~
  17. // CHECK:STDERR:
  18. var x: i32 = "hello"();
  19. }
  20. // CHECK:STDOUT: --- fail_not_callable.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %Run.type: type = fn_type @Run [concrete]
  24. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  25. // CHECK:STDOUT: %Run: %Run.type = struct_value () [concrete]
  26. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  27. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  28. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  30. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  31. // CHECK:STDOUT: %str: String = string_literal "hello" [concrete]
  32. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  33. // CHECK:STDOUT: %Op.type.bae: type = fn_type @Op.1 [concrete]
  34. // CHECK:STDOUT: %T.8b3: type = bind_symbolic_name T, 0 [symbolic]
  35. // CHECK:STDOUT: %Op.type.bc9: type = fn_type @Op.2, @impl.49c(%T.8b3) [symbolic]
  36. // CHECK:STDOUT: %Op.46f: %Op.type.bc9 = struct_value () [symbolic]
  37. // CHECK:STDOUT: %Destroy.impl_witness.64e: <witness> = impl_witness imports.%Destroy.impl_witness_table, @impl.49c(%i32) [concrete]
  38. // CHECK:STDOUT: %Op.type.a17: type = fn_type @Op.2, @impl.49c(%i32) [concrete]
  39. // CHECK:STDOUT: %Op.e6a: %Op.type.a17 = struct_value () [concrete]
  40. // CHECK:STDOUT: %ptr.235: type = ptr_type %i32 [concrete]
  41. // CHECK:STDOUT: %Destroy.facet: %Destroy.type = facet_value %i32, (%Destroy.impl_witness.64e) [concrete]
  42. // CHECK:STDOUT: %.ab7: type = fn_type_with_self_type %Op.type.bae, %Destroy.facet [concrete]
  43. // CHECK:STDOUT: %Op.specific_fn.014: <specific function> = specific_function %Op.e6a, @Op.2(%i32) [concrete]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  48. // CHECK:STDOUT: .Int = %Core.Int
  49. // CHECK:STDOUT: .Destroy = %Core.Destroy
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/...
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  54. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  55. // CHECK:STDOUT: %Core.import_ref.0b9: @impl.49c.%Op.type (%Op.type.bc9) = import_ref Core//prelude/destroy, loc15_29, loaded [symbolic = @impl.49c.%Op (constants.%Op.46f)]
  56. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (%Core.import_ref.0b9), @impl.49c [concrete]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: file {
  60. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  61. // CHECK:STDOUT: .Core = imports.%Core
  62. // CHECK:STDOUT: .Run = %Run.decl
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core.import = import Core
  65. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [concrete = constants.%Run] {} {}
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @Run() {
  69. // CHECK:STDOUT: !entry:
  70. // CHECK:STDOUT: name_binding_decl {
  71. // CHECK:STDOUT: %x.patt: %pattern_type.7ce = binding_pattern x [concrete]
  72. // CHECK:STDOUT: %x.var_patt: %pattern_type.7ce = var_pattern %x.patt [concrete]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %x.var: ref %i32 = var %x.var_patt
  75. // CHECK:STDOUT: %str: String = string_literal "hello" [concrete = constants.%str]
  76. // CHECK:STDOUT: assign %x.var, <error>
  77. // CHECK:STDOUT: %.loc19: type = splice_block %i32 [concrete = constants.%i32] {
  78. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  79. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %x: ref %i32 = bind_name x, %x.var
  82. // CHECK:STDOUT: %impl.elem0: %.ab7 = impl_witness_access constants.%Destroy.impl_witness.64e, element0 [concrete = constants.%Op.e6a]
  83. // CHECK:STDOUT: %bound_method.loc19_3.1: <bound method> = bound_method %x.var, %impl.elem0
  84. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Op.2(constants.%i32) [concrete = constants.%Op.specific_fn.014]
  85. // CHECK:STDOUT: %bound_method.loc19_3.2: <bound method> = bound_method %x.var, %specific_fn
  86. // CHECK:STDOUT: %addr: %ptr.235 = addr_of %x.var
  87. // CHECK:STDOUT: %no_op: init %empty_tuple.type = call %bound_method.loc19_3.2(%addr)
  88. // CHECK:STDOUT: return
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: