Files
carbon-lang/explorer/testdata/tuple/fail_implicit_convert_with_as.carbon
T
Richard Smith c8f18446f4 Support explicit conversion of tuples. (#2537)
Allow explicit conversion from a tuple of `T1`, `T2`, ... to a tuple of `U1`, `U2`, ... if each element has an explicit conversion.

Also add a comment to existing `ImplicitAs` impl for tuples explaining its purpose.
2023-01-19 14:56:01 -08:00

28 lines
751 B
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
// RUN: %{not} %{explorer-run}
// RUN: %{not} %{explorer-run-trace}
package ExplorerTest api;
class A {
var a: i32;
}
class B {
var b: i32;
}
external impl A as As(B) {
fn Convert[self: Self]() -> B { return {.b = self.a}; }
}
fn Main() -> i32 {
var a: (i32, A) = (1, {.a = 2});
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/tuple/fail_implicit_convert_with_as.carbon:[[@LINE+1]]: type error in name binding: '(i32, class A)' is not implicitly convertible to '(i32, class B)'
var b: (i32, B) = a;
return 0;
}