mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
A binding can have a constant value that is an `ErrorInst` during error recovery. In that case, deduction would crash when attempting to diagnose that the binding had no deduced value.
63 lines
2.1 KiB
Plaintext
63 lines
2.1 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/convert.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/deduce/binding_pattern.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/deduce/binding_pattern.carbon
|
|
|
|
// --- fail_incompatible_deduce.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C(T:! type) {
|
|
fn Create(unused value: T) {}
|
|
}
|
|
|
|
fn F(unused U:! type, V:! type) {
|
|
// CHECK:STDERR: fail_incompatible_deduce.carbon:[[@LINE+10]]:15: error: cannot implicitly convert expression of type `{}` to `V` [ConversionFailure]
|
|
// CHECK:STDERR: C(V).Create({});
|
|
// CHECK:STDERR: ^~
|
|
// CHECK:STDERR: fail_incompatible_deduce.carbon:[[@LINE+7]]:15: note: type `{}` does not implement interface `Core.ImplicitAs(V)` [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: C(V).Create({});
|
|
// CHECK:STDERR: ^~
|
|
// CHECK:STDERR: fail_incompatible_deduce.carbon:[[@LINE-10]]:20: note: initializing function parameter [InCallToFunctionParam]
|
|
// CHECK:STDERR: fn Create(unused value: T) {}
|
|
// CHECK:STDERR: ^~~~~~~~
|
|
// CHECK:STDERR:
|
|
C(V).Create({});
|
|
}
|
|
|
|
// --- compatible_deduce.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C(T:! type) {
|
|
fn Create(unused value: T) {}
|
|
}
|
|
|
|
// This `where` is sufficient to say that `{} as V` works.
|
|
fn F(unused U:! type, V:! Core.Destroy where {} impls Core.ImplicitAs(.Self)) {
|
|
C(V).Create({});
|
|
}
|
|
|
|
// --- fail_invalid_type.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class A {};
|
|
|
|
// CHECK:STDERR: fail_invalid_type.carbon:[[@LINE+4]]:10: error: name `DoesNotExist` not found [NameNotFound]
|
|
// CHECK:STDERR: fn F[T:! DoesNotExist](unused x: T) {}
|
|
// CHECK:STDERR: ^~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn F[T:! DoesNotExist](unused x: T) {}
|
|
|
|
fn Call(a: A) {
|
|
F(a);
|
|
}
|