mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:34:45 +01:00
Explorer: move subtyping logic to TypeChecker (#2484)
Addresses comments from this discussion: https://github.com/carbon-language/carbon-lang/pull/2460#discussion_r1046444433 Features: * Move subtyping logic from Interpreter to TypeChecker, exposing subtyping as a series of access to `.base`. * Excludes function parameter conversion, which is still done in ::Convert due to parameters conversion being handled differently. Changes: * Add new `class BaseAccessExpression : public MemberAccessExpression`, allowing rewrites * Handle `BaseAccessExpression` expression type in Interpreter * Move subtyping logic to `TypeChecker::ImplicitlyConvert`
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
// RUN: %{explorer-run}
|
||||
// RUN: %{explorer-run-trace}
|
||||
// CHECK:STDOUT: (*c).a: 1
|
||||
// CHECK:STDOUT: Foo(&d): 1
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
base class C {
|
||||
var a: i32;
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
}
|
||||
|
||||
fn Foo(c: C*) -> i32 {
|
||||
return (*c).a;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var d: D = { .base = {.a = 1} };
|
||||
var c: C* = &d;
|
||||
Print("(*c).a: {0}", (*c).a);
|
||||
Print("Foo(&d): {0}", Foo(&d));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user