mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 10:11:04 +01:00
Implementation of unused pattern bindings #2022, continued. Whereas previous PR #6460 took care of parsing, and PR #6479 prepared the stage by using _ in some test cases, this PR has the the actual implementation, using a simple dataflow analysis. --------- Co-authored-by: Burak Emir <bqe@google.com> Co-authored-by: jonmeow <jperkins@google.com>
82 lines
2.7 KiB
Plaintext
82 lines
2.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/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/symbolic_facets.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/deduce/symbolic_facets.carbon
|
|
|
|
// By placing each interface inside a generic class, a facet type refering to
|
|
// the interface becomes symbolic. Normally they would be concrete. This can
|
|
// affect decisions in deduce which unwraps symbolic constants, but still needs to
|
|
// ensure they convert correctly.
|
|
|
|
// --- fail_missing_interface.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C(CC:! type) {
|
|
interface A {}
|
|
fn F(unused T:! A) {}
|
|
}
|
|
|
|
class D(DD:! type) {
|
|
interface B {}
|
|
fn G(T:! B) {
|
|
// T only implements D(DD).B, so should not convert to a facet value
|
|
// implementing C(()).A.
|
|
//
|
|
// CHECK:STDERR: fail_missing_interface.carbon:[[@LINE+7]]:5: error: cannot convert type `T` that implements `B` into type implementing `A` [ConversionFailureFacetToFacet]
|
|
// CHECK:STDERR: C(()).F(T);
|
|
// CHECK:STDERR: ^~~~~~~~~~
|
|
// CHECK:STDERR: fail_missing_interface.carbon:[[@LINE-12]]:3: note: while deducing parameters of generic declared here [DeductionGenericHere]
|
|
// CHECK:STDERR: fn F(unused T:! A) {}
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
C(()).F(T);
|
|
}
|
|
}
|
|
|
|
// --- fail_interface_wrong_generic_param.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C(CC:! type) {
|
|
interface A {}
|
|
fn F(unused T:! A) {}
|
|
}
|
|
|
|
class D(DD:! type) {
|
|
interface B {}
|
|
fn G(T:! B & C({}).A) {
|
|
// T implements C({}).A and D(DD).B, so should not convert to a facet value
|
|
// implementing C(()).A.
|
|
//
|
|
// CHECK:STDERR: fail_interface_wrong_generic_param.carbon:[[@LINE+7]]:5: error: cannot convert type `T` that implements `A & B` into type implementing `A` [ConversionFailureFacetToFacet]
|
|
// CHECK:STDERR: C(()).F(T);
|
|
// CHECK:STDERR: ^~~~~~~~~~
|
|
// CHECK:STDERR: fail_interface_wrong_generic_param.carbon:[[@LINE-12]]:3: note: while deducing parameters of generic declared here [DeductionGenericHere]
|
|
// CHECK:STDERR: fn F(unused T:! A) {}
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
C(()).F(T);
|
|
}
|
|
}
|
|
|
|
// --- compatible_deduce.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C(CC:! type) {
|
|
interface A {}
|
|
fn F(unused T:! A) {}
|
|
}
|
|
|
|
class D(DD:! type) {
|
|
interface B {}
|
|
fn G(T:! B & C(()).A) {
|
|
C(()).F(T);
|
|
}
|
|
}
|