Files
carbon-lang/toolchain/check/testdata/impl/extend_impl.carbon
T
Richard SmithandJon Ross-Perkins 0e053703f8 Build Impl entity to represent an impl declaration. (#3683)
Collect the contents of an `impl` into a scope, and start doing very
basic checking for `impl` declarations and definitions.

This change adds two new `Id` types to the set of type that `NodeStack`
supports -- `ImplId` and `NameScopeId`.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2024-02-06 18:49:21 +00:00

80 lines
2.4 KiB
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 HasF {
fn F();
}
class C {
extend impl as HasF {
fn F() {}
}
}
fn G(c: C) {
// TODO: These don't do impl lookup, and so refer to the interface members
// rather than to the impl members.
C.F();
c.F();
}
// CHECK:STDOUT: --- extend_impl.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %C: type = class_type @C [template]
// CHECK:STDOUT: %.1: type = interface_type @HasF [template]
// CHECK:STDOUT: %.2: type = struct_type {} [template]
// CHECK:STDOUT: %.3: type = tuple_type () [template]
// CHECK:STDOUT: %.4: type = ptr_type {} [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {.HasF = %HasF.decl, .C = %C.decl, .G = %G} [template]
// CHECK:STDOUT: %HasF.decl = interface_decl @HasF, ()
// CHECK:STDOUT: %C.decl = class_decl @C, ()
// CHECK:STDOUT: %G: <function> = fn_decl @G [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: interface @HasF {
// CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .F = %F
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: impl @impl: C as HasF {
// CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .F = %F
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @C {
// CHECK:STDOUT: impl_decl @impl, (<unexpected instref inst+6>)
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: extend name_scope1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F.1();
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F.2() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @G(%c: C) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %C.ref: type = name_ref C, constants.%C [template = constants.%C]
// CHECK:STDOUT: %F.ref.loc20: <function> = name_ref F, @HasF.%F [template = @HasF.%F]
// CHECK:STDOUT: %.loc20: init () = call %F.ref.loc20()
// CHECK:STDOUT: %c.ref: C = name_ref c, %c
// CHECK:STDOUT: %F.ref.loc21: <function> = name_ref F, @HasF.%F [template = @HasF.%F]
// CHECK:STDOUT: %.loc21: init () = call %F.ref.loc21()
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: