mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 20:40:32 +00:00
By adding a constant to ClassDecl/InterfaceDecl, we're able to remove name reference special-casing. Use TryEvalInst on the Decl to generate the Type. For ClassDecl, then use the generated constant for self_type_id.
80 lines
2.5 KiB
Plaintext
80 lines
2.5 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: %.1: type = interface_type @HasF [template]
|
|
// CHECK:STDOUT: %C: type = class_type @C [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, () [template = constants.%.1]
|
|
// CHECK:STDOUT: %C.decl = class_decl @C, () [template = constants.%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, file.%C.decl [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:
|