mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Fuzz semantics when it passes parsing without errors. (#3003)
Right now we expect crashes on invalid parses, we just don't try to handle it in general even though the long-term intent is we should handle semantics for bad parses. However, in theory, we should be correctly handling code that parses as valid and that's probably more interesting to fix bugs for. So this starts trying to fuzz that space of valid parses. Fuzzer corpus is based on explorer tests, with one merge run.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# Exceptions. See /LICENSE for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test")
|
||||
load("//bazel/sh_run:rules.bzl", "glob_sh_run")
|
||||
load("//testing/file_test:rules.bzl", "file_test")
|
||||
|
||||
@@ -115,6 +116,17 @@ file_test(
|
||||
],
|
||||
)
|
||||
|
||||
cc_fuzz_test(
|
||||
name = "semantics_fuzzer",
|
||||
size = "small",
|
||||
srcs = ["semantics_fuzzer.cpp"],
|
||||
corpus = glob(["fuzzer_corpus/*"]),
|
||||
deps = [
|
||||
"//toolchain/driver",
|
||||
"@llvm-project//llvm:Support",
|
||||
],
|
||||
)
|
||||
|
||||
glob_sh_run(
|
||||
args = [
|
||||
"$(location //toolchain/driver:carbon)",
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn CompareStr(s: String) -> i32 {
|
||||
if (s == "str\n") {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return CompareStr("str\n");
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var t2: {.x: i32, .y: i32} = {.x = 2, .y = 5};
|
||||
t2.y = 3;
|
||||
// 3 - 2 - 1
|
||||
return t2.y - t2.x - 1;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
returned var x: i32;
|
||||
x = 1;
|
||||
return var;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 5
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class A {
|
||||
var n: i32;
|
||||
fn Get[self: Self]() -> i32 { return self.n; }
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return ({.n = 5} as A).Get();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface HasTypes {
|
||||
let A:! type;
|
||||
let B:! type;
|
||||
let C:! type;
|
||||
let D:! type;
|
||||
let E:! type;
|
||||
let F:! type;
|
||||
}
|
||||
|
||||
interface HasParams(A:! type, B:! type, C:! type, D:! type) {
|
||||
let V:! HasTypes;
|
||||
}
|
||||
|
||||
// Here we discover that there is a rewrite for `HasParams(...).V` only after
|
||||
// substitution converts each one to `HasParam(X, X, X, X).V`.
|
||||
fn F[X:! (HasTypes & HasParams(.Self, .Self, .Self, .Self)) where
|
||||
.Self impls HasParams(.A, .A, .A, .A) and
|
||||
.Self impls HasParams(.B, .B, .B, .B) and
|
||||
.Self impls HasParams(.C, .C, .C, .C) and
|
||||
.Self impls HasParams(.D, .D, .D, .D) and
|
||||
.Self impls HasParams(.E, .E, .E, .E) and
|
||||
.F = .Self.(HasParams(.E, .E, .E, .E).V).A and
|
||||
.E = .Self.(HasParams(.D, .D, .D, .D).V).A and
|
||||
.D = .Self.(HasParams(.C, .C, .C, .C).V).A and
|
||||
.C = .Self.(HasParams(.B, .B, .B, .B).V).A and
|
||||
.B = .Self.(HasParams(.A, .A, .A, .A).V).A and
|
||||
.A = .Self and .V = .Self](x: X) -> X.F { return x; }
|
||||
|
||||
impl i32 as HasTypes
|
||||
where .A = .B and .B = .C and .C = .D and .D = .E and .E = .F and .F = i32 {}
|
||||
impl i32 as HasParams(i32, i32, i32, i32) where .V = i32 {}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return F(0);
|
||||
}
|
||||
@@ -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
|
||||
package ExplorerTest api;
|
||||
|
||||
__mixin M1 {
|
||||
fn F1[self: Self](x: Self) -> Self{
|
||||
return x;
|
||||
}
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_recursive_mixing.carbon:[[@LINE+1]]: incomplete mixin `M1` used in mix declaration
|
||||
__mix M1;
|
||||
}
|
||||
|
||||
class C {
|
||||
__mix M1;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
choice Ints {
|
||||
None,
|
||||
One(i32),
|
||||
Two(i32, i32)
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
let (var Ints.Two(a1: auto, var a2: auto),
|
||||
((b: auto, var c: auto), var (d: auto, e: auto))) =
|
||||
(Ints.Two(1, 10), ((2, 3), (4, 5)));
|
||||
a1 = 0;
|
||||
a2 = 0;
|
||||
c = 0;
|
||||
d = 0;
|
||||
e = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn ReturnSecond(_: i32, x: i32) -> i32 {
|
||||
return x;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return ReturnSecond(1, 0);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class Point(T:! type) {
|
||||
fn Create(x: T, y: T) -> Point(T) {
|
||||
return {.x = x, .y = y};
|
||||
}
|
||||
|
||||
var x: T;
|
||||
var y: T;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_generic_class_arg.carbon:[[@LINE+1]]: wrong number of arguments in function call, expected 1 but got 2
|
||||
var p: Point(i32) = Point(i32, i32).Create(0, 1);
|
||||
return p.x;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// Test a global variable depending on another global.
|
||||
|
||||
var x: i32 = 0;
|
||||
|
||||
var y: i32 = x;
|
||||
|
||||
fn Main() -> i32 {
|
||||
return y;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: SYNTAX ERROR: fail_newline.carbon:[[@LINE+2]]: missing closing quote in single-line string: "new
|
||||
// CHECK:STDERR:
|
||||
Print("new
|
||||
line");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn snd[T:! type](x: i32, y: T) -> T {
|
||||
return y;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return snd(0, 1);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Iface {
|
||||
let T:! type;
|
||||
}
|
||||
|
||||
fn F[T:! Iface where .T == i32](x: T) {}
|
||||
|
||||
fn G[U:! Iface where .T == i32](x: U) {
|
||||
F(x);
|
||||
}
|
||||
|
||||
fn H[V:! Iface](x: V) {
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_equal_to_dependent_type.carbon:[[@LINE+1]]: constraint requires that (T).(Iface.T) (with value (V).(Iface.T)) == i32, which is not known to be true
|
||||
F(x);
|
||||
}
|
||||
|
||||
class Class {
|
||||
extend impl as Iface where .T = i32 {}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: Class = {};
|
||||
G(x);
|
||||
H(x);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
returned var x: i32 = 1;
|
||||
if (true) {
|
||||
var x: i32 = 2;
|
||||
return var;
|
||||
}
|
||||
x = 3;
|
||||
return var;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class C {}
|
||||
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_combine_rhs.carbon:[[@LINE+1]]: expected a constraint in second operand of `&`, found class C
|
||||
fn F[T:! type & C]();
|
||||
|
||||
fn Main() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_no_impl.carbon:[[@LINE+1]]: i32 is not equality comparable with String (could not find implementation of interface EqWith(U = String) for i32)
|
||||
Print("different types equal: {0}", if 1 == "1" then 1 else 0);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_compound_assign.carbon:[[@LINE+1]]: use of uninitialized variable x
|
||||
x += 1;
|
||||
return x;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: A
|
||||
// CHECK:STDOUT: c.a: 1
|
||||
// CHECK:STDOUT: c.b: 2
|
||||
// CHECK:STDOUT: c.c: 3
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
base class A {
|
||||
fn FunctionA() {}
|
||||
var a: i32;
|
||||
var aa: String;
|
||||
}
|
||||
|
||||
base class B {
|
||||
extend base: A;
|
||||
fn FunctionB() {}
|
||||
var b: i32;
|
||||
}
|
||||
|
||||
class C {
|
||||
extend base: B;
|
||||
fn FunctionC() {}
|
||||
var c: i32;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var c: C = {.base={.base={.aa="A", .a=1}, .b=2, }, .c=3};
|
||||
c.FunctionA();
|
||||
c.FunctionB();
|
||||
c.FunctionC();
|
||||
Print(c.aa);
|
||||
Print("c.a: {0}", c.a);
|
||||
Print("c.b: {0}", c.b);
|
||||
Print("c.c: {0}", c.c);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class Point(T:! type, V:! T) {
|
||||
fn Get[self: Self]() -> T {
|
||||
return V;
|
||||
}
|
||||
}
|
||||
|
||||
fn F(p: Point(i32, 1)) -> i32 {
|
||||
return p.Get();
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var v: Point(i32, 1) = {};
|
||||
return F(v);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Vector {
|
||||
fn Add[self: Self](b: Self) -> Self;
|
||||
fn Scale[self: Self](v: i32) -> Self;
|
||||
}
|
||||
|
||||
class Point {
|
||||
var x: i32;
|
||||
var y: i32;
|
||||
extend impl as Vector {
|
||||
fn Add[self: Point](b: Point) -> Point {
|
||||
return {.x = self.x + b.x, .y = self.y + b.y};
|
||||
}
|
||||
fn Scale[self: Point](v: i32) -> Point {
|
||||
return {.x = self.x * v, .y = self.y * v};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ScaleGeneric[U:! Vector](c: U, s: i32) -> U {
|
||||
return c.Scale(s);
|
||||
}
|
||||
|
||||
fn AddAndScaleGeneric[T:! Vector](a: T, b: T, s: i32) -> T {
|
||||
return ScaleGeneric(a.Add(b), s);
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: Point = {.x = 1, .y = 1};
|
||||
var b: Point = {.x = 2, .y = 3};
|
||||
var p: Point = AddAndScaleGeneric(a, b, 5);
|
||||
return p.x - 15;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn CompareStr(s: String) -> i32 {
|
||||
if (s == ##"str"##) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return CompareStr(#####"str"#####);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// TODO: Implement this with some kind of reflection?
|
||||
impl {.x: i32, .y: i32} as EqWith(Self) {
|
||||
fn Equal[self: Self](other: Self) -> bool {
|
||||
return self.x == other.x and self.y == other.y;
|
||||
}
|
||||
fn NotEqual[self: Self](other: Self) -> bool {
|
||||
return self.x != other.x or self.y != other.y;
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var t1: {.x: i32, .y: i32} = {.x = 5, .y = 2};
|
||||
var t2: {.x: i32,} = {.x = 5,};
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_equality_type.carbon:[[@LINE+1]]: {.x: i32, .y: i32} is not equality comparable with {.x: i32} (could not find implementation of interface EqWith(U = {.x: i32}) for {.x: i32, .y: i32})
|
||||
if (t1 == t2) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn F() {}
|
||||
alias A = F;
|
||||
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_wrong_fn_alias_use.carbon:[[@LINE+1]]: alias A cannot be used as a name qualifier
|
||||
fn A.Foo() {}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
|
||||
package EmptyIdentifier impl;
|
||||
|
||||
fn A() {
|
||||
// CHECK:STDERR: RUNTIME ERROR: fail_function_recursion.carbon:[[@LINE+1]]: stack overflow: too many interpreter actions on stack
|
||||
A();
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
A();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_rhs_def.carbon:[[@LINE+1]]: use of uninitialized variable x
|
||||
var y: i32 = x;
|
||||
return x;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: i32 = 1;
|
||||
let a_pinned: i32 = a;
|
||||
// OK: Value unused after being mutated.
|
||||
a = 2;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: DESTRUCTOR A 1
|
||||
// CHECK:STDOUT: DESTRUCTOR A 2
|
||||
// CHECK:STDOUT: DESTRUCTOR A 3
|
||||
// CHECK:STDOUT: DESTRUCTOR A 4
|
||||
// CHECK:STDOUT: result: 2
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class A{
|
||||
destructor[self: Self]{
|
||||
Print("DESTRUCTOR A {0}",self.n);
|
||||
}
|
||||
var n: i32;
|
||||
}
|
||||
|
||||
fn ident(x: bool)-> bool{
|
||||
return x;
|
||||
}
|
||||
|
||||
fn ident_i32(x: i32)-> i32{
|
||||
return x;
|
||||
}
|
||||
// It should be enforced that different runtime scopes are on the stack.
|
||||
//So that it can be tested that the wrong scopes are not removed from the stack.
|
||||
fn Main() -> i32 {
|
||||
var i: i32 = 0;
|
||||
var d: A = {.n = 4};
|
||||
if(ident(true)){
|
||||
var a: A = {.n = 3};
|
||||
if(true){
|
||||
var b: A = {.n = 2};
|
||||
ident_i32(2);
|
||||
if(ident_i32(0) == 0){
|
||||
var c: A = {.n = 1};
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: SYNTAX ERROR: fail_raw_block_more_hash_tags_on_right.carbon:[[@LINE+1]]: invalid character '\x23' in source file.
|
||||
var s: String = #'''
|
||||
error: there are more #s on the right than the left.
|
||||
'''##;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 2
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
var call_count: i32 = 0;
|
||||
fn ReturnFalse() -> bool {
|
||||
call_count = call_count + 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var result: bool = ReturnFalse() or ReturnFalse();
|
||||
return if not result then call_count else -1;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
abstract class B {
|
||||
}
|
||||
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_instantiate_global_abstract.carbon:[[@LINE+1]]: Cannot instantiate abstract class B
|
||||
var b: B = {};
|
||||
|
||||
fn Main() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn add1(x: i32) -> i32 {
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var f: __Fn(i32)->i32 = add1;
|
||||
return f(-1);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Has(T:! type) {
|
||||
fn Get() -> T;
|
||||
}
|
||||
impl i32 as Has(type) {
|
||||
fn Get() -> type { return Self; }
|
||||
}
|
||||
|
||||
class WithType(T:! Has(type)) {
|
||||
fn Get() -> type { return T.Get(); }
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var v: WithType(i32).Get() = 0;
|
||||
return v;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
constraint X {
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_associated_constant.carbon:[[@LINE+1]]: associated constant not permitted in named constraint
|
||||
let N:! type;
|
||||
}
|
||||
|
||||
fn Main() -> i32 { return 0; }
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn CompareStr(s: String) -> i32 {
|
||||
if (s == "str;\x07") {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return CompareStr("\x73\x74\x72\x3B\x07");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_destination_not_type.carbon:[[@LINE+1]]: type error in type expression: 'i32' is not implicitly convertible to 'type'
|
||||
return 4 as 7;
|
||||
}
|
||||
@@ -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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn IntDiff(a: i32, b: i32) -> i32 {
|
||||
if (a == b) {
|
||||
returned var ret: i32 = a - b;
|
||||
return var;
|
||||
} else {
|
||||
returned var ret2: i32 = b - a;
|
||||
return var;
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return IntDiff(1, 2);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: c.Foo() -> 1
|
||||
// CHECK:STDOUT: c.Bar() -> 2
|
||||
// CHECK:STDOUT: d.Foo() -> 3
|
||||
// CHECK:STDOUT: d.Bar() -> 4
|
||||
// CHECK:STDOUT: cc.Foo() -> 3
|
||||
// CHECK:STDOUT: cc.Bar() -> 2
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
base class C {
|
||||
virtual fn Foo[self: Self]() -> i32 {
|
||||
return 1;
|
||||
}
|
||||
fn Bar[self: Self]() -> i32 {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
class D {
|
||||
extend base: C;
|
||||
impl fn Foo[self: Self]() -> i32 {
|
||||
return 3;
|
||||
}
|
||||
fn Bar[self: Self]() -> i32 {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var c: C = {};
|
||||
Print("c.Foo() -> {0}", c.Foo());
|
||||
Print("c.Bar() -> {0}", c.Bar());
|
||||
var d: D = {.base = {}};
|
||||
Print("d.Foo() -> {0}", d.Foo());
|
||||
Print("d.Bar() -> {0}", d.Bar());
|
||||
var cc: C* = &d;
|
||||
Print("cc.Foo() -> {0}", (*cc).Foo());
|
||||
Print("cc.Bar() -> {0}", (*cc).Bar());
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class Point {
|
||||
var x: i32;
|
||||
var y: i32;
|
||||
}
|
||||
|
||||
var p: Point = {.x = 1, .y = 2};
|
||||
|
||||
fn Main() -> i32 {
|
||||
return p.y - p.x - 1;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn fst[T:! type](x: T, y: T) -> T {
|
||||
return x;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return fst(0, 1);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class C {
|
||||
fn F() {}
|
||||
fn G[self: Self]() {}
|
||||
}
|
||||
|
||||
fn H[T:! type](x: T) {}
|
||||
|
||||
fn Main() -> i32 {
|
||||
H(C.F);
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_method_deduced.carbon:[[@LINE+1]]: member name G can only be used in a member access or alias
|
||||
H(C.G);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_field_value.carbon:[[@LINE+1]]: use of uninitialized variable x
|
||||
var p: auto = {.x = x,};
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
x = 1;
|
||||
return x;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: Foo(c1): 1
|
||||
// CHECK:STDOUT: Foo(c2): 1
|
||||
// CHECK:STDOUT: Foo(d): 1
|
||||
// CHECK:STDOUT: Foo(&e): 1
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
base class C {
|
||||
var val: i32;
|
||||
}
|
||||
|
||||
base class D {
|
||||
extend base: C;
|
||||
var val: i32;
|
||||
}
|
||||
|
||||
class E {
|
||||
extend base: D;
|
||||
var val: i32;
|
||||
}
|
||||
|
||||
fn Foo(c: C*) -> i32 {
|
||||
return (*c).val;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var e: E = { .val = 3, .base = {.val = 2,.base = {.val = 1}}};
|
||||
var d: D* = &e;
|
||||
var c1: C* = &e;
|
||||
var c2: C* = d;
|
||||
|
||||
Print("Foo(c1): {0}", Foo(c1));
|
||||
Print("Foo(c2): {0}", Foo(c2));
|
||||
Print("Foo(d): {0}", Foo(d));
|
||||
Print("Foo(&e): {0}", Foo(&e));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: 1
|
||||
// CHECK:STDOUT: 2
|
||||
// CHECK:STDOUT: 3
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
base class A {
|
||||
var a: i32;
|
||||
}
|
||||
|
||||
base class B {
|
||||
extend base: A;
|
||||
var b: i32;
|
||||
}
|
||||
|
||||
class C {
|
||||
extend base: B;
|
||||
var c: i32;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var c: C = {.base = {.base = {.a = 1}, .b = 2}, .c = 3};
|
||||
let (pa: A*, pb: B*, pc: C*) = (&c, &c, &c);
|
||||
Print("{0}", pa->a);
|
||||
Print("{0}", pb->b);
|
||||
Print("{0}", pc->c);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: Class 1
|
||||
// CHECK:STDOUT: Class 2
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
base class C {
|
||||
fn BasePrint(v: i32) {
|
||||
Print("Class {0}", v);
|
||||
}
|
||||
fn Method1[self: Self]() {
|
||||
self.BasePrint(self.value_c);
|
||||
}
|
||||
|
||||
var value_c: i32;
|
||||
}
|
||||
|
||||
class D {
|
||||
extend base: C;
|
||||
fn Method2[self: Self]() {
|
||||
self.BasePrint(self.value_d);
|
||||
}
|
||||
|
||||
var value_d: i32;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var d: D = {.base = {.value_c = 1}, .value_d = 2};
|
||||
d.Method1();
|
||||
d.Method2();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Vector {
|
||||
fn Add[self: Self](b: Self) -> Self;
|
||||
fn Scale[self: Self](v: i32) -> Self;
|
||||
}
|
||||
|
||||
class Point1 {
|
||||
var x: i32;
|
||||
var y: i32;
|
||||
extend impl as Vector {
|
||||
fn Add[self: Point1](b: Point1) -> Point1 {
|
||||
return {.x = self.x + b.x, .y = self.y + b.y};
|
||||
}
|
||||
fn Scale[self: Point1](v: i32) -> Point1 {
|
||||
return {.x = self.x * v, .y = self.y * v};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Point2 {
|
||||
var x: i32;
|
||||
var y: i32;
|
||||
extend impl as Vector {
|
||||
fn Add[self: Point2](b: Point2) -> Point2 {
|
||||
return {.x = self.x + b.x + 1, .y = self.y + b.y + 1};
|
||||
}
|
||||
fn Scale[self: Point2](v: i32) -> Point2 {
|
||||
return {.x = self.x * v * 2, .y = self.y * v * 2};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ScaleGeneric[U:! Vector](c: U, s: i32) -> U {
|
||||
return c.Scale(s);
|
||||
}
|
||||
|
||||
fn AddAndScaleGeneric[T:! Vector, V:! Vector](a: T, b: V, s: i32) -> (T, V) {
|
||||
return (ScaleGeneric(a.Add(a), s),
|
||||
ScaleGeneric(b.Add(b), s));
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: Point1 = {.x = 1, .y = 1};
|
||||
var b: Point2 = {.x = 2, .y = 3};
|
||||
var (p: Point1, q: Point2) = AddAndScaleGeneric(a, b, 5);
|
||||
return q.x - p.x - 40;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Iface {
|
||||
let N:! i32;
|
||||
}
|
||||
|
||||
fn F(T:! Iface where .N == 5) {}
|
||||
|
||||
class Good {}
|
||||
class Bad {}
|
||||
impl Good as Iface where .N = 5 {}
|
||||
impl Bad as Iface where .N = 4 {}
|
||||
|
||||
fn Main() -> i32 {
|
||||
F(Good);
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_different_value.carbon:[[@LINE+1]]: constraint requires that (T).(Iface.N) (with value 4) == 5, which is not known to be true
|
||||
F(Bad);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 4
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
alias TypeAlias = i32;
|
||||
|
||||
fn Main() -> TypeAlias {
|
||||
var n: TypeAlias = 1;
|
||||
var m: i32 = n;
|
||||
var p: i32* = &n;
|
||||
var q: TypeAlias* = &m;
|
||||
return *p + *q + m + n;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn F() {}
|
||||
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_qualifier_not_namespace.carbon:[[@LINE+1]]: fn F cannot be used as a name qualifier
|
||||
fn F.G() {}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
Assert(true, "HALLO WELT");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: 6
|
||||
// CHECK:STDOUT: 5
|
||||
// CHECK:STDOUT: 6
|
||||
// CHECK:STDOUT: 5
|
||||
// CHECK:STDOUT: 6
|
||||
// CHECK:STDOUT: 5
|
||||
// CHECK:STDOUT: 6
|
||||
// CHECK:STDOUT: 5
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class A { var n: i32; }
|
||||
|
||||
impl A as Inc {
|
||||
fn Op[addr self: Self*]() { ++self->n; }
|
||||
}
|
||||
impl A as Dec {
|
||||
fn Op[addr self: Self*]() { --self->n; }
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: A = {.n = 5};
|
||||
++a.n;
|
||||
Print("{0}", a.n);
|
||||
--a.n;
|
||||
Print("{0}", a.n);
|
||||
++a;
|
||||
Print("{0}", a.n);
|
||||
--a;
|
||||
Print("{0}", a.n);
|
||||
a.n.(Inc.Op)();
|
||||
Print("{0}", a.n);
|
||||
a.n.(Dec.Op)();
|
||||
Print("{0}", a.n);
|
||||
a.(Inc.Op)();
|
||||
Print("{0}", a.n);
|
||||
a.(Dec.Op)();
|
||||
Print("{0}", a.n);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package Foo api;
|
||||
interface A { fn F[self: Self]() -> i32; }
|
||||
class X {
|
||||
extend impl as A {
|
||||
fn F[self: Self]() -> i32 { return 1; }
|
||||
}
|
||||
}
|
||||
fn Main() -> i32 {
|
||||
var a: X = {};
|
||||
return a.(X.(A.F))();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest impl;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: RUNTIME ERROR: fail_single_brace.carbon:[[@LINE+1]]: `{` must be followed by a second `{` or index in `{`
|
||||
Print("{");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_nontype_tuple_as_type.carbon:[[@LINE+1]]: type error in type of name binding: '(i32, i32)' is not implicitly convertible to 'type'
|
||||
fn F[T:! (i32, i32)](x: T);
|
||||
|
||||
fn Main() -> i32;
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface X { fn F(); }
|
||||
impl i32 as X { fn F() {} }
|
||||
|
||||
fn G[T:! X](v: T) -> type {
|
||||
v.F();
|
||||
return i32;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var v: G(0) = 0;
|
||||
return v;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest impl;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: RUNTIME ERROR: fail_index_bounds1.carbon:[[@LINE+1]]: Index invalid with argument count of 1 at offset 12 in `Print: {0} {1}`
|
||||
Print("Print: {0} {1}", 1);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn add(x: i32, y: i32) -> auto { return x + y; }
|
||||
|
||||
fn Main() -> i32 {
|
||||
return add(1, 2) - 3;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: 8
|
||||
// CHECK:STDOUT: 4
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
if (1 << 0 != 1) { return 1; }
|
||||
if (1 << 3 != 8) { return 2; }
|
||||
if (0 << 3 != 0) { return 3; }
|
||||
if (3 << 1 != 6) { return 4; }
|
||||
if (-1 << 2 != -4) { return 5; }
|
||||
if (1 >> 0 != 1) { return 6; }
|
||||
if (1 >> 1 != 0) { return 7; }
|
||||
if (3 >> 1 != 1) { return 8; }
|
||||
if (-1 >> 1 != -1) { return 9; }
|
||||
if (-2 >> 1 != -1) { return 10; }
|
||||
|
||||
var n: i32 = 1;
|
||||
n <<= 3;
|
||||
Print("{0}", n);
|
||||
n >>= 1;
|
||||
Print("{0}", n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: RUNTIME ERROR: fail_overflow_add.carbon:[[@LINE+1]]: integer overflow
|
||||
var a: auto = 2147483647 + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn CompareStr(s: String) -> i32 {
|
||||
if (s == "HELLO WORLD!!") {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return CompareStr("\u{0048}\u{0045}\u{004C}\u{004C}\u{004F} \u{0057}\u{004F}\u{0052}\u{004C}\u{0044}\u{0021}\u{21}");
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class C {}
|
||||
|
||||
// CHECK:STDERR: SYNTAX ERROR: fail_type_only.carbon:[[@LINE+1]]: syntax error, unexpected RIGHT_SQUARE_BRACKET, expecting COLON
|
||||
fn f[x:! i32, addr C]() {}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Vector {
|
||||
fn Zero() -> Self;
|
||||
fn Add[self: Self](b: Self) -> Self;
|
||||
fn Scale[self: Self](v: i32) -> Self;
|
||||
}
|
||||
|
||||
class Point(T:! type) {
|
||||
var x: T;
|
||||
var y: T;
|
||||
}
|
||||
|
||||
impl Point(i32) as Vector {
|
||||
// Allowed: `Self` means `Point(i32)` here.
|
||||
fn Zero() -> Self {
|
||||
return {.x = 0, .y = 0};
|
||||
}
|
||||
|
||||
fn Add[self: Self](b: Self) -> Self {
|
||||
return {.x = self.x + b.x, .y = self.y + b.y};
|
||||
}
|
||||
|
||||
fn Scale[self: Self](v: i32) -> Self {
|
||||
return {.x = self.x * v, .y = self.y * v};
|
||||
}
|
||||
}
|
||||
|
||||
fn AddAndScaleGeneric[T:! Vector](a: T, s: i32) -> T {
|
||||
return a.Add(T.Zero()).Scale(s);
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: Point(i32) = {.x = 2, .y = 1};
|
||||
var p: Point(i32) = AddAndScaleGeneric(a, 5);
|
||||
return p.x - 10;
|
||||
}
|
||||
@@ -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
|
||||
// CHECK:STDOUT: result: 2
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Vector {
|
||||
let Dim:! i32;
|
||||
}
|
||||
|
||||
class Point {
|
||||
var x: i32;
|
||||
var y: i32;
|
||||
extend impl as Vector where .Dim = 2 {}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return Point.(Vector.Dim);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 3
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class TypeLike {
|
||||
extend impl as ImplicitAs(type) {
|
||||
fn Convert[self: Self]() -> type { return i32; }
|
||||
}
|
||||
fn Make() -> Self { return {}; }
|
||||
}
|
||||
|
||||
fn Main() -> TypeLike.Make() {
|
||||
var x: {.a: TypeLike.Make(), .b: TypeLike.Make()} = {.a = 1, .b = 2};
|
||||
return x.a + x.b;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
if (0 == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
|
||||
package EmptyIdentifier impl;
|
||||
|
||||
fn Main() -> i32 {
|
||||
while (true) {
|
||||
// Ideally we would hit an OOM here, but it's too difficult to OOM from heap
|
||||
// allocations before hitting max steps. Maybe with string operations we
|
||||
// could trigger actual excessive memory allocations by just doubling the
|
||||
// size of the string each time.
|
||||
// CHECK:STDERR: RUNTIME ERROR: fail_allocate.carbon:[[@LINE+1]]: possible infinite loop: too many interpreter steps executed
|
||||
heap.New((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn CompareStr(s: String) -> i32 {
|
||||
// CHECK:STDERR: SYNTAX ERROR: fail_raw_block_single_line.carbon:[[@LINE+1]]: Invalid block string: Too few lines
|
||||
if (s == #'''raw string literal starting with '''#) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return CompareStr("\"\"raw string literal starting with \"\"");
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: i32;
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: RUNTIME ERROR: fail_div_by_zero.carbon:[[@LINE+1]]: division by zero
|
||||
var a: auto = 5 / 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn ReturnIndirectly[T:! type](direct: bool, x: T) -> type {
|
||||
if (direct) {
|
||||
return T;
|
||||
} else {
|
||||
return ReturnIndirectly(true, x);
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> ReturnIndirectly(false, 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
class A(T:! type) {
|
||||
var v: T;
|
||||
}
|
||||
fn F(T:! type, x: T) -> T {
|
||||
var v: A(T) = {.v = x};
|
||||
return v.v;
|
||||
}
|
||||
fn Main() -> i32 {
|
||||
return F(i32, 1);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: MemberF.F
|
||||
// CHECK:STDOUT: ImplF.(HasF.F)
|
||||
// CHECK:STDOUT: BothFs.(HasF.F)
|
||||
// CHECK:STDOUT: BothFs.F
|
||||
// CHECK:STDOUT: BothFs.F
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
choice ImplKind {
|
||||
Checked,
|
||||
ConstrainedTemplate,
|
||||
UnconstrainedTemplate
|
||||
}
|
||||
|
||||
interface CallF(K:! ImplKind) {
|
||||
fn DoIt[self: Self]();
|
||||
}
|
||||
|
||||
interface HasF {
|
||||
fn F[self: Self]();
|
||||
}
|
||||
|
||||
impl forall [T:! HasF] T as CallF(ImplKind.Checked) {
|
||||
fn DoIt[self: Self]() { self.F(); }
|
||||
}
|
||||
|
||||
impl forall [template T:! HasF] T as CallF(ImplKind.ConstrainedTemplate) {
|
||||
fn DoIt[self: Self]() { self.F(); }
|
||||
}
|
||||
|
||||
impl forall [template T:! type] T as CallF(ImplKind.UnconstrainedTemplate) {
|
||||
fn DoIt[self: Self]() { self.F(); }
|
||||
}
|
||||
|
||||
class MemberF {
|
||||
fn F[self: Self]() { Print("MemberF.F"); }
|
||||
}
|
||||
|
||||
class ImplF {}
|
||||
impl ImplF as HasF {
|
||||
fn F[self: Self]() { Print("ImplF.(HasF.F)"); }
|
||||
}
|
||||
|
||||
class BothFs {
|
||||
fn F[self: Self]() { Print("BothFs.F"); }
|
||||
}
|
||||
impl BothFs as HasF {
|
||||
fn F[self: Self]() { Print("BothFs.(HasF.F)"); }
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var mem: MemberF = {};
|
||||
var imp: ImplF = {};
|
||||
var both: BothFs = {};
|
||||
|
||||
mem.(CallF(ImplKind.UnconstrainedTemplate).DoIt)();
|
||||
|
||||
imp.(CallF(ImplKind.Checked).DoIt)();
|
||||
// TODO: Should be valid, but currently fails during instantiation.
|
||||
//imp.(CallF(ImplKind.ConstrainedTemplate).DoIt)();
|
||||
|
||||
both.(CallF(ImplKind.Checked).DoIt)();
|
||||
// TODO: Should be rejected, but currently incorrectly accepted.
|
||||
// This line can be deleted once it starts failing; we test that this is
|
||||
// rejected in fail_name_lookup.carbon.
|
||||
both.(CallF(ImplKind.ConstrainedTemplate).DoIt)();
|
||||
both.(CallF(ImplKind.UnconstrainedTemplate).DoIt)();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
if (0 == 1) {
|
||||
return 1;
|
||||
} else if (0 == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var n: i32 = 0;
|
||||
match (n) {
|
||||
case 1 => { return 0; }
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface I {}
|
||||
impl i32 as I {}
|
||||
|
||||
fn F(A:! i32, B:! i32, C:! i32, D:! i32, E:! i32,
|
||||
T:! I where A == B and C == D and C == E and B == D) {
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_combine_equality.carbon:[[@LINE+1]]: member access, F not in interface I where T impls interface I and A == B and C == D and C == E and B == D
|
||||
T.F();
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
F(1, 1, 1, 1, 1, i32);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 6
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
namespace N;
|
||||
|
||||
fn OuterI32() -> type { return i32; }
|
||||
fn One() -> i32 { return 1; }
|
||||
|
||||
fn N.I32() -> type { return i32; }
|
||||
fn N.Five() -> I32() { return 5; }
|
||||
fn N.Six() -> OuterI32() { return Five() + One(); }
|
||||
|
||||
fn Main() -> i32 { return N.Six(); }
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
__mixin M1 {
|
||||
fn Scale10[self: Self](x:i32) -> i32{
|
||||
return x * 10;
|
||||
}
|
||||
}
|
||||
|
||||
__mixin M2 {
|
||||
__mix M1;
|
||||
fn Square[self: Self](x:i32) -> i32{
|
||||
return x * x;
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
__mix M2;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var c: C = {};
|
||||
return c.Square(11) - c.Scale10(10) - 21;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class C {
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_use_before_typecheck.carbon:[[@LINE+1]]: incomplete type `class C` used in member access
|
||||
var n: if not C.WrapInStruct() then i32 else {.n: i32};
|
||||
fn WrapInStruct() -> bool { return true; }
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
var x: i32;
|
||||
|
||||
fn Main() -> i32 {
|
||||
x = 1;
|
||||
return x;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var x: [[i32; 3]; 2] = ((0, 1, 2), (3, 4, 5));
|
||||
return x[1][2] - 5;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: bool: 1
|
||||
// CHECK:STDOUT: bool: 1
|
||||
// CHECK:STDOUT: bool: 1
|
||||
// CHECK:STDOUT: bool: 1
|
||||
// CHECK:STDOUT: bool: 1
|
||||
// CHECK:STDOUT: bool: 1
|
||||
// CHECK:STDOUT: bool: 1
|
||||
// CHECK:STDOUT: bool: 1
|
||||
// CHECK:STDOUT: string: 1
|
||||
// CHECK:STDOUT: string: 1
|
||||
// CHECK:STDOUT: string: 1
|
||||
// CHECK:STDOUT: string: 1
|
||||
// CHECK:STDOUT: string: 1
|
||||
// CHECK:STDOUT: string: 1
|
||||
// CHECK:STDOUT: string: 1
|
||||
// CHECK:STDOUT: string: 1
|
||||
// CHECK:STDOUT: int: 1
|
||||
// CHECK:STDOUT: int: 1
|
||||
// CHECK:STDOUT: int: 1
|
||||
// CHECK:STDOUT: int: 1
|
||||
// CHECK:STDOUT: int: 1
|
||||
// CHECK:STDOUT: int: 1
|
||||
// CHECK:STDOUT: int: 1
|
||||
// CHECK:STDOUT: int: 1
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn CompareEqualValues[T:! EqWith(.Self)](format: String, a: T, b: T) {
|
||||
Print(format, if a == b then 1 else 0);
|
||||
Print(format, if a != b then 0 else 1);
|
||||
}
|
||||
|
||||
fn CompareDifferentValues[U:! EqWith(.Self)](format: String, a: U, b: U) {
|
||||
Print(format, if a == b then 0 else 1);
|
||||
Print(format, if a != b then 1 else 0);
|
||||
}
|
||||
|
||||
fn CompareAll[V:! EqWith(.Self)](format: String, a: V, b: V) {
|
||||
CompareEqualValues(format, a, a);
|
||||
CompareEqualValues(format, b, b);
|
||||
CompareDifferentValues(format, a, b);
|
||||
CompareDifferentValues(format, b, a);
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
CompareAll("bool: {0}", false, true);
|
||||
CompareAll("string: {0}", "hello", "world");
|
||||
CompareAll("int: {0}", 1, 2);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: DESTRUCTOR A 1
|
||||
// CHECK:STDOUT: DESTRUCTOR B 2
|
||||
// CHECK:STDOUT: DESTRUCTOR A 3
|
||||
// CHECK:STDOUT: DESTRUCTOR A 4
|
||||
// CHECK:STDOUT: DESTRUCTOR A 5
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class A{
|
||||
destructor[self: Self]{
|
||||
Print("DESTRUCTOR A {0}",self.n);
|
||||
}
|
||||
fn Create(x: i32) -> A{
|
||||
return {.n = x};
|
||||
}
|
||||
var n: i32;
|
||||
}
|
||||
|
||||
class B{
|
||||
destructor[self: Self]{
|
||||
Print("DESTRUCTOR B {0}",self.n);
|
||||
}
|
||||
fn Create(x: i32) -> B{
|
||||
return {.n = x, .a1 = A.Create(4),.a2 = A.Create(3) };
|
||||
}
|
||||
var a1: A;
|
||||
var n: i32;
|
||||
var a2: A;
|
||||
}
|
||||
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: A = A.Create(5);
|
||||
var b: B = B.Create(2);
|
||||
var c: A = A.Create(1);
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class A {
|
||||
fn F[self: Self]() -> i32;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: A = {};
|
||||
// CHECK:STDERR: RUNTIME ERROR: fail_call_undefined_method.carbon:[[@LINE+1]]: attempt to call function `F` that has not been defined
|
||||
return a.F();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: SYNTAX ERROR: fail_octal.carbon:[[@LINE+1]]: Invalid escaping in string: "str\01"
|
||||
Print("str\01");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var (x: i32, y: i32);
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_while_cond.carbon:[[@LINE+1]]: use of uninitialized variable x
|
||||
while (x == 0) {
|
||||
y = 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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
|
||||
|
||||
package Foo api;
|
||||
fn F[self: i32]() {}
|
||||
fn Main() -> i32 {
|
||||
// TODO: It's unclear whether this is valid per the current rules. See
|
||||
// https://github.com/carbon-language/carbon-lang/pull/1122
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_qualified_non_member.carbon:[[@LINE+1]]: expected name of instance member or interface member in compound member access, found fn [self: i32]() -> ()
|
||||
42.(F)();
|
||||
return 0;
|
||||
}
|
||||
@@ -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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class Point {
|
||||
fn Origin() -> Point {
|
||||
return {.x = 0, .y = 0};
|
||||
}
|
||||
|
||||
var x: i32;
|
||||
var y: i32;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var p: Point = Point.Origin();
|
||||
return p.x;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Container {
|
||||
let Element:! type;
|
||||
fn Front[self: Self]() -> Element;
|
||||
}
|
||||
|
||||
fn A[T:! Container where .Element = i32](x: T) -> T.Element {
|
||||
return x.Front();
|
||||
}
|
||||
|
||||
fn B[T:! Container](x: T) -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: fail_missing_rewrite.carbon:[[@LINE+1]]: constraint requires that (T).(Container.Element) (with value (T).(Container.Element)) == i32, which is not known to be true
|
||||
return A(x);
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: Initialize c1 from initializing expression (returned var)
|
||||
// CHECK:STDOUT: Before nested init
|
||||
// CHECK:STDOUT: 0: Heap{}, 1: !Uninit<class C>
|
||||
// CHECK:STDOUT: Nested call return
|
||||
// CHECK:STDOUT: 0: Heap{}, 1: C{}
|
||||
// CHECK:STDOUT: First call return
|
||||
// CHECK:STDOUT: 0: Heap{}, 1: C{}
|
||||
// CHECK:STDOUT: Declaration scope
|
||||
// CHECK:STDOUT: 0: Heap{}, 1: C{}
|
||||
// CHECK:STDOUT: c destroyed
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class C {
|
||||
destructor[self: Self] {
|
||||
Print("c destroyed");
|
||||
}
|
||||
}
|
||||
|
||||
fn CallWithReturnedVar2() -> C {
|
||||
Print("Before nested init");
|
||||
heap.PrintAllocs();
|
||||
returned var c: C = {};
|
||||
Print("Nested call return");
|
||||
heap.PrintAllocs();
|
||||
return var;
|
||||
}
|
||||
|
||||
fn CallWithReturnedVar() -> C {
|
||||
returned var c: C = CallWithReturnedVar2();
|
||||
Print("First call return");
|
||||
heap.PrintAllocs();
|
||||
return var;
|
||||
}
|
||||
|
||||
fn FromInitializingExpression_ReturnedVar() {
|
||||
Print("Initialize c1 from initializing expression (returned var)");
|
||||
let c: C = CallWithReturnedVar();
|
||||
Print("Declaration scope");
|
||||
heap.PrintAllocs();
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
FromInitializingExpression_ReturnedVar();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: 6
|
||||
// CHECK:STDOUT: 3
|
||||
// CHECK:STDOUT: 1
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class A { var n: i32; }
|
||||
|
||||
impl A as DivWith(i32) where .Result = A {
|
||||
fn Op[self: Self](rhs: i32) -> A { return {.n = self.n / rhs}; }
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: A = {.n = 19};
|
||||
a = a / 3;
|
||||
Print("{0}", a.n);
|
||||
a /= 2;
|
||||
Print("{0}", a.n);
|
||||
Print("{0}", (a / 2).n);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: DESTRUCTOR A 1
|
||||
// CHECK:STDOUT: DESTRUCTOR A 2
|
||||
// CHECK:STDOUT: DESTRUCTOR A 3
|
||||
// CHECK:STDOUT: DESTRUCTOR A 1
|
||||
// CHECK:STDOUT: DESTRUCTOR A 2
|
||||
// CHECK:STDOUT: DESTRUCTOR A 3
|
||||
// CHECK:STDOUT: result: 1
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class A{
|
||||
destructor[self: Self]{
|
||||
Print("DESTRUCTOR A {0}",self.n);
|
||||
}
|
||||
var n: i32;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var i: i32 = 0;
|
||||
while( i < 2){
|
||||
var a: A = {.n = 3};
|
||||
var b: A = {.n = 2};
|
||||
var c: A = {.n = 1};
|
||||
i = i + 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: 3
|
||||
// CHECK:STDOUT: 4
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a: (i32, i32) = (1, 2);
|
||||
var p: (i32, i32)* = &a;
|
||||
|
||||
a[0] = 3;
|
||||
Print("{0}", (*p)[0]);
|
||||
|
||||
(*p)[1] = 4;
|
||||
Print("{0}", a[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32{
|
||||
var x: Optional(String) = Optional(String).CreateEmpty();
|
||||
if(x.HasValue()){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 12
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var cond: if true then bool else i32 = true;
|
||||
if (if cond then true else false) {}
|
||||
while (if cond then false else true) {}
|
||||
return if if cond then true or false else false and true
|
||||
then if not cond then 1 + 2 else 3 * 4
|
||||
else if not cond then 5 + 6 else 7 * 8;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
var p: i32* = __intrinsic_new(0);
|
||||
var y: i32 = *p;
|
||||
__intrinsic_delete(p);
|
||||
return y;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: Allocate D
|
||||
// CHECK:STDOUT: DESTRUCTOR B
|
||||
// CHECK:STDOUT: DESTRUCTOR A
|
||||
// CHECK:STDOUT: DESTRUCTOR D
|
||||
// CHECK:STDOUT: DESTRUCTOR C
|
||||
// CHECK:STDOUT: Delete B from A*
|
||||
// CHECK:STDOUT: DESTRUCTOR B
|
||||
// CHECK:STDOUT: DESTRUCTOR A
|
||||
// CHECK:STDOUT: Delete D from C*
|
||||
// CHECK:STDOUT: DESTRUCTOR D
|
||||
// CHECK:STDOUT: DESTRUCTOR C
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
base class A {
|
||||
virtual destructor[self: Self] {
|
||||
Print("DESTRUCTOR A");
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
extend base: A;
|
||||
fn Create() -> Self{
|
||||
return {.base={}};
|
||||
}
|
||||
impl destructor[self: Self] {
|
||||
Print("DESTRUCTOR B");
|
||||
}
|
||||
}
|
||||
|
||||
base class C {
|
||||
virtual destructor[self: Self] {
|
||||
Print("DESTRUCTOR C");
|
||||
}
|
||||
}
|
||||
|
||||
class D {
|
||||
extend base: C;
|
||||
fn Create() -> Self{
|
||||
return {.base={}, .d_pa=heap.New(B.Create())};
|
||||
}
|
||||
impl destructor[self: Self] {
|
||||
Print("DESTRUCTOR D");
|
||||
}
|
||||
var d_pa: A*;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
Print("Allocate D");
|
||||
var pd: D* = heap.New(D.Create());
|
||||
var pc: C* = pd;
|
||||
|
||||
Print("Delete B from A*");
|
||||
heap.Delete(pd->d_pa);
|
||||
|
||||
Print("Delete D from C*");
|
||||
heap.Delete(pc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class Point(T:! type) {
|
||||
fn Origin(zero: T) -> Point(T) {
|
||||
return {.x = zero, .y = zero};
|
||||
}
|
||||
|
||||
fn GetX[self: Point(T)]() -> T {
|
||||
return self.x;
|
||||
}
|
||||
|
||||
var x: T;
|
||||
var y: T;
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var p: Point(i32) = Point(i32).Origin(0);
|
||||
return p.GetX();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// 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
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// Check that even generic parameters are looked up in the namespace of an
|
||||
// entity.
|
||||
namespace N;
|
||||
|
||||
interface N.Interface {}
|
||||
|
||||
class N.A(T:! Interface) {}
|
||||
interface N.B(T:! Interface) {}
|
||||
constraint N.C(T:! Interface) {}
|
||||
__mixin N.D(T:! Interface) {}
|
||||
choice N.E(T:! Interface) {}
|
||||
fn N.F[T:! Interface](a: A(T)) {}
|
||||
|
||||
fn Main() -> i32 { return 0; }
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: RUNTIME ERROR: fail_overflow_multiply.carbon:[[@LINE+1]]: integer overflow
|
||||
var a: auto = 1000000000 * 1000000000;
|
||||
return 0;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user