aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-05 20:32:06 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-05 20:32:06 -0400
commit1d8b8ad687facd25a27b3ff6d083812b45cd529f (patch)
tree8f21e06cbbd22156a8d36f214aa4e52bff8f175c /test/compile_errors.zig
parent8400163e0245f68833e29db22ae3bcc1fb8bf9ae (diff)
downloadzig-1d8b8ad687facd25a27b3ff6d083812b45cd529f.tar.gz
zig-1d8b8ad687facd25a27b3ff6d083812b45cd529f.zip
add compile error for using outer scoped runtime variables
from a fn defined inside it. closes #876
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 00fc33d122..24d977c218 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -2,6 +2,26 @@ const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
+ "accessing runtime parameter from outer function",
+ \\fn outer(y: u32) fn (u32) u32 {
+ \\ const st = struct {
+ \\ fn get(z: u32) u32 {
+ \\ return z + y;
+ \\ }
+ \\ };
+ \\ return st.get;
+ \\}
+ \\export fn entry() void {
+ \\ var func = outer(10);
+ \\ var x = func(3);
+ \\}
+ ,
+ ".tmp_source.zig:4:24: error: 'y' not accessible from inner function",
+ ".tmp_source.zig:3:28: note: crossed function definition here",
+ ".tmp_source.zig:1:10: note: declared here",
+ );
+
+ cases.add(
"non int passed to @intToFloat",
\\export fn entry() void {
\\ const x = @intToFloat(f32, 1.1);