Files
carbon-lang/executable_semantics/testdata/choice1.carbon
T
Jon Meow a03536a196 Add syntax for package and library (#792)
Doesn't add much logic, only takes advantage of parser structure for the ordering enforcement.

Note import_nonexistent tests should probably fail, but writing import tests needs a chain of functionality, and I figured I'd just start adding some to validate the syntax (not adding existent imports because that'd require multi-file structure).
2021-09-02 16:01:15 -07:00

42 lines
804 B
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
package ExecutableSemanticsTest api;
choice Ints {
None,
One(i32),
Two(i32,i32)
}
fn main() -> i32 {
var x: auto = Ints.None();
var y: auto = Ints.One(42);
var n: auto = 0;
match (y) {
case Ints.None =>
n = n + 2;
case Ints.One(x: auto) =>
n = x + 1 - 42;
case Ints.Two(a: auto, b: auto) =>
n = 2;
}
match (x) {
case Ints.One(x: auto) =>
n = x + 2;
case Ints.None() =>
n = n - 1;
case Ints.Two(x: auto, y: auto) =>
n = 5;
}
return n;
}
// Test some alternate syntaxes
choice MoreInts {
None(),
One(i32),
Two(i32,i32),
}