mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 07:10:09 +01:00
These functions are dangerous, as they check whether conversions are possible without actually performing the conversions. In each case where they were used, explorer would crash in some cases if a user-defined conversion is required. This change moves us more towards implicit conversions being handled by a regular function call on an interface and away from them being magical builtins. Unfortunately, this exposes a pre-existing bug that a call of the form `x.(ImplicitAs(T).Convert)()` compiles even if `x` only has an explicit conversion to `T`. That's worked around here for now, but will need a proper fix later.
28 lines
767 B
Plaintext
28 lines
767 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 initializer of variable: '(i32, class A)' is not implicitly convertible to '(i32, class B)'
|
|
var b: (i32, B) = a;
|
|
return b[1].b;
|
|
}
|