From dc5851e87373203f5c64b9f15872e2865ab85f3f Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 28 Aug 2018 12:16:14 +0200 Subject: [PATCH] added a test to ensure that for-loop-variables cannot be mutated --- tests/varres/tprevent_forloopvar_mutations.nim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/varres/tprevent_forloopvar_mutations.nim diff --git a/tests/varres/tprevent_forloopvar_mutations.nim b/tests/varres/tprevent_forloopvar_mutations.nim new file mode 100644 index 000000000..15938bb77 --- /dev/null +++ b/tests/varres/tprevent_forloopvar_mutations.nim @@ -0,0 +1,15 @@ +discard """ + line: 15 + errmsg: "type mismatch: got " + nimout: '''type mismatch: got +but expected one of: +proc inc[T: Ordinal | uint | uint64](x: var T; y = 1) + for a 'var' type a variable needs to be passed, but 'i' is immutable + +expression: inc i +''' +""" + +for i in 0..10: + echo i + inc i