Files
carbon-lang/toolchain/check/testdata/function/call/fail_not_callable.carbon
T
Richard SmithandJon Ross-Perkins 57f3c553b8 Support for type-checking and lowering method calls. (#3343)
Adds a `BoundMethod` SemIR node to represent an `x.F` bound method, with
a new builtin type `BoundMethodType`. Reorganized conversion of call
expression arguments to also check and convert a `self` parameter in the
implicit parameters list.

In passing, improved diagnostics and error recovery for bad call
expressions. We now build a `call` node with the appropriate type and
value category, but with invalid arguments, if the argument conversion
failed, and diagnose calls to non-callable expressions.

`addr self` methods don't work properly yet; the `addr` is ignored for
now.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-10-27 20:41:13 +00:00

27 lines
931 B
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
fn Run() {
// CHECK:STDERR: fail_not_callable.carbon:[[@LINE+3]]:23: ERROR: Value of type `String` is not callable.
// CHECK:STDERR: var x: i32 = "hello"();
// CHECK:STDERR: ^
var x: i32 = "hello"();
}
// CHECK:STDOUT: file "fail_not_callable.carbon" {
// CHECK:STDOUT: %Run: <function> = fn_decl @Run
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Run() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %x.var: ref i32 = var "x"
// CHECK:STDOUT: %x: ref i32 = bind_name "x", %x.var
// CHECK:STDOUT: %.1: type = ptr_type String
// CHECK:STDOUT: %.loc11: String = string_literal "hello"
// CHECK:STDOUT: assign %x.var, <error>
// CHECK:STDOUT: return
// CHECK:STDOUT: }