aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authorVexu <git@vexu.eu>2020-05-04 14:28:58 +0300
committerVexu <git@vexu.eu>2020-05-04 14:28:58 +0300
commitadc444ceeb91c06a6ee84dc4e4874294a41dee45 (patch)
treed69253d7044ad741b64ee61abed86d8a2cb7a890 /test/compile_errors.zig
parente72f45475d05fb446e48d3e34e6c8e367916bd50 (diff)
downloadzig-adc444ceeb91c06a6ee84dc4e4874294a41dee45.tar.gz
zig-adc444ceeb91c06a6ee84dc4e4874294a41dee45.zip
fix missing compile error on call assigned to const
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index fd27b8e666..3d7677ab75 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -2,6 +2,29 @@ const tests = @import("tests.zig");
const std = @import("std");
pub fn addCases(cases: *tests.CompileErrorContext) void {
+ cases.add("call assigned to constant",
+ \\const Foo = struct {
+ \\ x: i32,
+ \\};
+ \\fn foo() Foo {
+ \\ return .{ .x = 42 };
+ \\}
+ \\fn bar(val: var) Foo {
+ \\ return .{ .x = val };
+ \\}
+ \\export fn entry() void {
+ \\ const baz: Foo = undefined;
+ \\ baz = foo();
+ \\}
+ \\export fn entry1() void {
+ \\ const baz: Foo = undefined;
+ \\ baz = bar(42);
+ \\}
+ , &[_][]const u8{
+ "tmp.zig:12:14: error: cannot assign to constant",
+ "tmp.zig:16:14: error: cannot assign to constant",
+ });
+
cases.add("invalid pointer syntax",
\\export fn foo() void {
\\ var guid: *:0 const u8 = undefined;