mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:30:14 +01:00
Instead of building the definition of a thunk immediately when we generate the thunk declaration, wait until we reach the `}` of the outermost class, interface, etc. -- at the same time when we would parse the definition of the thunk if it were defined inline. This fixes issues where we fail to define the thunk because it requires an enclosing class to be complete, or its definition depends on something declared later in the enclosing class. Make the representation of a suspended function scope, and its constituent suspended components, be move-only, and switch to passing it around by rvalue reference instead of by value because it's expensive both to move and especially to copy. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
43 lines
1.3 KiB
Plaintext
43 lines
1.3 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
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/min_prelude/convert.carbon
|
|
// EXTRA-ARGS: --no-dump-sem-ir --custom-core
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/min_prelude/impl_thunk.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/min_prelude/impl_thunk.carbon
|
|
|
|
// --- convert_in_class.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface X(T:! type, U:! type) {
|
|
fn F(t: T) -> U;
|
|
}
|
|
|
|
class ConvertsToA {}
|
|
class ConvertsToB {}
|
|
|
|
// Check that we don't try to define a thunk for `A.B.(as X).F` until we reach
|
|
// the end of `A`. If we tried earlier, we wouldn't find a conversion from
|
|
// `ConvertsToA` to `A` or from `ConvertsToB` to `B`.
|
|
class A {
|
|
class B {
|
|
impl as X(ConvertsToA, B) {
|
|
fn F(a: A) -> ConvertsToB;
|
|
}
|
|
|
|
impl ConvertsToB as Core.ImplicitAs(B) {
|
|
fn Convert[self: Self]() -> B { return {}; }
|
|
}
|
|
}
|
|
|
|
impl ConvertsToA as Core.ImplicitAs(A) {
|
|
fn Convert[self: Self]() -> A { return {}; }
|
|
}
|
|
}
|