mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 03:36:39 +00:00
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>
34 lines
916 B
Plaintext
34 lines
916 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
|
|
|
|
class C {
|
|
var a: i32;
|
|
|
|
fn Get[self: C]() -> i32;
|
|
fn Set[addr self: C*](n: i32);
|
|
}
|
|
|
|
fn F(p: C*) {
|
|
let n: i32 = (*p).Get();
|
|
// TODO: Support `addr self`.
|
|
// (*p).Set(n);
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'method.carbon'
|
|
// CHECK:STDOUT: source_filename = "method.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: declare i32 @Get(ptr)
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: declare void @Set(ptr, i32)
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define void @F(ptr %p) {
|
|
// CHECK:STDOUT: %Get = call i32 @Get(ptr %p)
|
|
// CHECK:STDOUT: %temp = alloca i32, align 4
|
|
// CHECK:STDOUT: store i32 %Get, ptr %temp, align 4
|
|
// CHECK:STDOUT: %1 = load i32, ptr %temp, align 4
|
|
// CHECK:STDOUT: ret void
|
|
// CHECK:STDOUT: }
|