mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-01 15:56:01 +01:00
Add basic support for `match_first` declarations to explorer, as described in https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/generics/details.md#prioritization-rule. The concrete syntax here is not yet approved, so `match_first` is renamed to `__match_first` for now, but the semantics are necessary to implement other approved features in explorer so we're intentionally getting a little ahead of the design here.
37 lines
1.0 KiB
Plaintext
37 lines
1.0 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
|
|
//
|
|
// AUTOUPDATE
|
|
// RUN: %{not} %{explorer-run}
|
|
// RUN: %{not} %{explorer-run-trace}
|
|
|
|
package ExplorerTest api;
|
|
|
|
class A(T:! type) {}
|
|
interface B(T:! type) {}
|
|
|
|
// This match_first doesn't affect the ambiguity between
|
|
// these impls and the one below.
|
|
// TODO: Once we order by type structure, the second impl
|
|
// in this block should win.
|
|
__match_first {
|
|
external impl A(i32) as B(i32) {}
|
|
external impl forall [T:! type] A(i32) as B(T) {}
|
|
}
|
|
|
|
external impl forall [T:! type] A(T) as B(i32) {}
|
|
|
|
fn F[T:! B(i32)](x: T) {}
|
|
fn G[T:! B(bool)](x: T) {}
|
|
|
|
fn Main() -> i32 {
|
|
let a: A(bool) = {};
|
|
let b: A(i32) = {};
|
|
F(a);
|
|
G(b);
|
|
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/impl/fail_ambiguous_impl_match_first.carbon:[[@LINE+1]]: ambiguous implementations of interface B(T = i32) for class A(T = i32)
|
|
F(b);
|
|
return 0;
|
|
}
|