mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 22:02:33 +01:00
On the parsing side, we treat `a.(b)` as a member access whose second operand is a `ParenExpr` rather than a `MemberName`. A new node category is added for the union of `MemberName` and `ParenExpr` to support this. Checking is mostly reusing the same pieces we already have for simple member access. Compound member access is in most ways a simplified form of simple member access because it doesn't need to do any lookup.
38 lines
883 B
Plaintext
38 lines
883 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
|
|
|
|
interface I {
|
|
fn F[self: Self]() -> i32;
|
|
}
|
|
|
|
class A {
|
|
var n: i32;
|
|
}
|
|
|
|
impl A as I {
|
|
fn F[self: A]() -> i32 {
|
|
return self.n;
|
|
}
|
|
}
|
|
|
|
fn Call(a: A) -> i32 {
|
|
return a.(I.F)();
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'impl.carbon'
|
|
// CHECK:STDOUT: source_filename = "impl.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @F(ptr %self) {
|
|
// CHECK:STDOUT: %n = getelementptr inbounds { i32 }, ptr %self, i32 0, i32 0
|
|
// CHECK:STDOUT: %1 = load i32, ptr %n, align 4
|
|
// CHECK:STDOUT: ret i32 %1
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @Call(ptr %a) {
|
|
// CHECK:STDOUT: %F = call i32 @F(ptr %a)
|
|
// CHECK:STDOUT: ret i32 %F
|
|
// CHECK:STDOUT: }
|