Files
carbon-lang/toolchain/check/testdata/class/adapter/convert_incomplete.carbon
T
Richard Smith 1331ade57f Attempt to complete the source type in a conversion. (#5984)
This is necessary if the source type is an adapter, as we would not
otherwise be able to determine what type it adapts and hence could be
converted to.
2025-08-26 00:33:12 +00:00

64 lines
1.7 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/testdata/min_prelude/int.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/adapter/convert_incomplete.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/adapter/convert_incomplete.carbon
// --- already_complete.carbon
library "[[@TEST_NAME]]";
class Adapter(T:! type) {
extend adapt T*;
}
class X {}
// Trigger completion of Adapter(X) here.
var x: Adapter(X);
fn F(p: Adapter(X)*) {
let x: X* = *p as X*;
}
// --- can_be_completed.carbon
library "[[@TEST_NAME]]";
class Adapter(T:! type) {
extend adapt T*;
}
class X {}
fn F(p: Adapter(X)*) {
// The conversion here triggers completion of Adapter(X)
// so we can determine what it adapts.
let x: X* = *p as X*;
}
// --- fail_incomplete.carbon
library "[[@TEST_NAME]]";
class Adapter(T:! type);
class X {}
fn F(p: Adapter(X)*) {
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE+7]]:15: error: cannot convert expression of type `Adapter(X)` to `X*` with `as` [ConversionFailure]
// CHECK:STDERR: let x: X* = *p as X*;
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE+4]]:15: note: type `Adapter(X)` does not implement interface `Core.As(X*)` [MissingImplInMemberAccessNote]
// CHECK:STDERR: let x: X* = *p as X*;
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
let x: X* = *p as X*;
}