mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Start doing more validation of intrinsics: assert, new, delete, rand (#2766)
This is adding more validation of intrinsics. It addresses a bug in rand where CHECK-fails would occur for bad range inputs, instead of a runtime error. I'm also addressing what I think was an int32 range issue in the handling by running the generator with int64.
This commit is contained in:
+15
@@ -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
|
||||
// RUN: %{explorer-run}
|
||||
// RUN: %{explorer-run-trace}
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
Assert(true, "HALLO WELT");
|
||||
return 0;
|
||||
}
|
||||
+22
@@ -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: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class ConvertTo(T:! type) {
|
||||
var v: T;
|
||||
impl as ImplicitAs(T) {
|
||||
fn Convert[self: Self]() -> T { return self.v; }
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
Assert({.v = true} as ConvertTo(bool), {.v = "Pass"} as ConvertTo(String));
|
||||
return 0;
|
||||
}
|
||||
-1
@@ -10,7 +10,6 @@
|
||||
package ExplorerTest api;
|
||||
|
||||
fn Main() -> i32 {
|
||||
Assert(true, "HALLO WELT");
|
||||
Assert(false, "HALLO WELT");
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-5
@@ -5,6 +5,7 @@
|
||||
// AUTOUPDATE
|
||||
// RUN: %{not} %{explorer-run}
|
||||
// RUN: %{not} %{explorer-run-trace}
|
||||
// CHECK:STDERR: RUNTIME ERROR: {{.*}}/explorer/data/prelude.carbon:{{.*}}: "Fail"
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
@@ -16,10 +17,6 @@ class ConvertTo(T:! type) {
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assert/fail_convert.carbon:[[@LINE+3]]: type error in __intrinsic_assert argument 0
|
||||
// CHECK:STDERR: expected: bool
|
||||
// CHECK:STDERR: actual: class ConvertTo(T = bool)
|
||||
__intrinsic_assert({.v = true} as ConvertTo(bool), {.v = "Pass"} as ConvertTo(String));
|
||||
__intrinsic_assert({.v = false} as ConvertTo(bool), {.v = "Fail"} as ConvertTo(String));
|
||||
Assert({.v = false} as ConvertTo(bool), {.v = "Fail"} as ConvertTo(String));
|
||||
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
|
||||
// RUN: %{not} %{explorer-run}
|
||||
// RUN: %{not} %{explorer-run-trace}
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class ConvertTo(T:! type) {
|
||||
var v: T;
|
||||
impl as ImplicitAs(T) {
|
||||
fn Convert[self: Self]() -> T { return self.v; }
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: SYNTAX ERROR: {{.*}}/explorer/testdata/assert/fail_intrinsic_bool_type.carbon:[[@LINE+1]]: syntax error, unexpected COMMA
|
||||
__intrinsic_assert(, "unused");
|
||||
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
|
||||
// RUN: %{not} %{explorer-run}
|
||||
// RUN: %{not} %{explorer-run-trace}
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class ConvertTo(T:! type) {
|
||||
var v: T;
|
||||
impl as ImplicitAs(T) {
|
||||
fn Convert[self: Self]() -> T { return self.v; }
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assert/fail_intrinsic_no_args.carbon:[[@LINE+1]]: __intrinsic_assert takes 2 arguments
|
||||
__intrinsic_assert();
|
||||
return 0;
|
||||
}
|
||||
@@ -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
|
||||
// RUN: %{not} %{explorer-run}
|
||||
// RUN: %{not} %{explorer-run-trace}
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class ConvertTo(T:! type) {
|
||||
var v: T;
|
||||
impl as ImplicitAs(T) {
|
||||
fn Convert[self: Self]() -> T { return self.v; }
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assert/fail_intrinsic_no_convert.carbon:[[@LINE+3]]: type error in __intrinsic_assert argument 0
|
||||
// CHECK:STDERR: expected: bool
|
||||
// CHECK:STDERR: actual: class ConvertTo(T = bool)
|
||||
__intrinsic_assert({.v = true} as ConvertTo(bool), {.v = "Pass"} as ConvertTo(String));
|
||||
return 0;
|
||||
}
|
||||
@@ -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
|
||||
// RUN: %{not} %{explorer-run}
|
||||
// RUN: %{not} %{explorer-run-trace}
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class ConvertTo(T:! type) {
|
||||
var v: T;
|
||||
impl as ImplicitAs(T) {
|
||||
fn Convert[self: Self]() -> T { return self.v; }
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assert/fail_intrinsic_str_type.carbon:[[@LINE+3]]: type error in __intrinsic_assert argument 1
|
||||
// CHECK:STDERR: expected: String
|
||||
// CHECK:STDERR: actual: i32
|
||||
__intrinsic_assert(true, 1);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user