mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Make type contexts expect a value of type Type. (#2357)
In particular, this means that a type can implement `ImplicitAs(Type)` and have values of that type behave like types.
This implies that `()` and `{}` are no longer types. They are now values whose type is the result of converting `()` or `{}` to type `Type`, as has been discussed recently and seems to be the supported direction. This fixes various cases where these types were previously mishandled.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// 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: %{explorer-run}
|
||||
// RUN: %{explorer-run-trace}
|
||||
// CHECK:STDOUT: result: 3
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class TypeLike {
|
||||
impl as ImplicitAs(Type) {
|
||||
fn Convert[me: Self]() -> Type { return i32; }
|
||||
}
|
||||
fn Make() -> Self { return {}; }
|
||||
}
|
||||
|
||||
fn Main() -> TypeLike.Make() {
|
||||
var v: [TypeLike.Make(); 2] = (1, 2);
|
||||
return v[0] + v[1];
|
||||
}
|
||||
Reference in New Issue
Block a user