mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 11:06:03 +01:00
Factor out a Pattern sum type from Expression (#685)
`Pattern` is intended to pilot some changes I would like to apply to all our sum types: - The alternatives are expressed as derived classes rather than members of a `std::variant`. - The alternatives are classes in the [style guide sense](https://google.github.io/styleguide/cppguide.html#Structs_vs._Classes), meaning they can have invariants, but can't have public data members. - Creating an object is expressed using a constructor rather than a factory function. - Accessing an alternative is expressed as a cast (using LLVM's RTTI system) rather than `std::get` or a `Get` method. Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
parent
b08f6bb0f1
commit
6ac3adfa53
+3
-1
@@ -1,2 +1,4 @@
|
||||
COMPILATION ERROR: 10: tuples of different length
|
||||
COMPILATION ERROR: 10: type error in call
|
||||
expected: (0 = Int, 1 = Int)
|
||||
actual: (0 = (0 = Int, 1 = Int))
|
||||
EXIT CODE: 255
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
// 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
|
||||
|
||||
fn main() -> Int {
|
||||
var t: auto = fnty (Int,Int);
|
||||
var x: Int = 0;
|
||||
match (t) {
|
||||
case z: Type =>
|
||||
x = x + 1;
|
||||
}
|
||||
match (t) {
|
||||
case fnty(a: Type,b: Type) =>
|
||||
x = x - 1;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
result: 0
|
||||
@@ -1,2 +1,2 @@
|
||||
COMPILATION ERROR: 7: pattern variables are only allowed in pattern context
|
||||
executable_semantics/testdata/pattern_variable_fail.carbon:7: syntax error, unexpected :
|
||||
EXIT CODE: 255
|
||||
|
||||
Reference in New Issue
Block a user