if n_expr != null then
v.generate_stmt(n_expr)
v.iroutine.closure_decls[position].default = iclos
+
+ # Add a final break in case of break block witout value
+ if variable.closure.is_break and v.return_value == null then
+ v.stmt(new IEscape(v.return_seq.as(not null)))
+ end
end
v.seq = old_seq
end
v.generate_stmt(n_expr)
+ # Add a final break in case of break block witout value
+ if closure.is_break and escapable.break_value == null then
+ v.stmt(new IEscape(escapable.break_seq.as(not null)))
+ end
+
v.seq = seq_old
_iclosure_def = iclos
return iclos
if v.variable_ctx.unreash == false then
if variable.closure.signature.return_type != null then
v.error(self, "Control error: Reached end of block (a 'continue' with a value was expected).")
- else if variable.closure.is_break then
- v.error(self, "Control error: Reached end of break block (an 'abort' was expected).")
+ else if variable.closure.is_break and escapable.break_list != null then
+ v.error(self, "Control error: Reached end of break block (a 'break' with a value was expected).")
end
end
end
if v.variable_ctx.unreash == false then
if closure.signature.return_type != null then
v.error(self, "Control error: Reached end of block (a 'continue' with a value was expected).")
- else if closure.is_break then
- v.error(self, "Control error: Reached end of break block (a 'break' was expected).")
+ else if closure.is_break and esc.break_list != null then
+ v.error(self, "Control error: Reached end of break block (a 'break' with a value was expected).")
end
end
v.variable_ctx = old_var_ctx
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import kernel
+
+class A
+ fun foo: Int
+ break !bar #!alt12#
+ #alt12#break !bar: Int
+ do
+ 1.output
+ bar #!alt1#
+ #alt2#bar(2)
+ #alt3#var x = bar
+ return 4
+ end
+end
+
+fun work
+do
+ var a = new A
+ var r = a.foo !bar do #!alt11#
+ #alt11#var r = a.foo !bar x do
+ 2.output
+ #alt4#break 4
+ #alt5#break 'x'
+ #alt6#continue
+ #alt7#continue 'x'
+ #alt8#return
+ #alt9#return 'x'
+ 3.output
+ break 4 #!alt13#
+ end
+ r.output
+ #alt10# a.foo
+ 5.output
+end
+
+0.output
+work
+6.output
+
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import kernel
+
+class A
+ fun foo
+ break !bar do
+ #alt1# return
+ #alt2# return 1
+ #alt3# abort
+ #alt4# continue
+ #alt5# continue 20
+ #alt6# break
+ #alt7# break 1
+ 20.output
+ end
+ do
+ 1.output
+ bar
+ 3.output
+ end
+end
+
+var a = new A
+0.output
+a.foo !bar do 2.output
+0.output
+a.foo
+0.output
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import kernel
+
+class A
+ fun foo: Int
+ break !bar do
+ #alt1# return
+ #alt2# return 1
+ #alt3# abort
+ #alt4# continue
+ #alt5# continue 20
+ #alt6# break
+ #alt7# break 1
+ #alt8# break 'x'
+ break 20#!alt9#
+ end
+ do
+ 1.output
+ bar
+ 3.output
+ end
+end
+
+var a = new A
+0.output
+var x = a.foo !bar do break 2
+x.output
+0.output
+x = a.foo
+x.output
+0.output
!error(e) do
'E'.output
e.output
- break
end
if f_escape != null then
'O'.output
--- /dev/null
+0
+1
+2
+3
+4
+5
+6
--- /dev/null
+0
+1
+4
+5
+6
--- /dev/null
+alt/base_closure_break2_alt10.nit:48,3--7: Error: foo requires 1 blocks.
--- /dev/null
+alt/base_closure_break2_alt11.nit:35,17--44,9: Error: 0 automatic variable names expected, 1 found.
--- /dev/null
+alt/base_closure_break2_alt12.nit:21,3--17: Syntax Error: A break block cannot have a return value.
--- /dev/null
+alt/base_closure_break2_alt13.nit:35,16--44,10: Control error: Reached end of break block (a 'break' with a value was expected).
--- /dev/null
+alt/base_closure_break2_alt2.nit:26,3--7: Error: arity missmatch; prototype is 'bar'.
--- /dev/null
+alt/base_closure_break2_alt3.nit:27,11--13: Type error: expected expression.
--- /dev/null
+0
+1
+2
+4
+5
+6
--- /dev/null
+alt/base_closure_break2_alt5.nit:39,9--11: Type error: no most general type. Got Char and Int at 45,9.
--- /dev/null
+alt/base_closure_break2_alt6.nit:40,3--10: Error: cannot 'continue', only 'break'.
--- /dev/null
+alt/base_closure_break2_alt7.nit:41,3--14: Error: cannot 'continue', only 'break'.
--- /dev/null
+0
+1
+2
+6
--- /dev/null
+alt/base_closure_break2_alt9.nit:43,3--12: Error: Return with value in a procedure.
-alt/base_closure_break_alt13.nit:35,8--44,10: Control error: Reached end of break block (a 'break' was expected).
+0
+1
+2
+3
+5
+6
--- /dev/null
+0
+1
+2
+0
+1
+20
+0
--- /dev/null
+0
+1
+2
+0
+1
+20
+0
--- /dev/null
+alt/base_closure_break_default2_alt1.nit:22,5--10: Error: Return without value in a function.
--- /dev/null
+0
+1
+2
+0
+1
+1
+0
--- /dev/null
+0
+1
+2
+0
+1
+Aborted (alt/base_closure_break_default2_alt3.nit:24)
+,---- Stack trace -- - - -
+| base_closure_break_default2_alt3::A::foo (alt/base_closure_break_default2_alt3.nit:20)
+| base_closure_break_default2_alt3::Sys::(kernel::Sys::main) (alt/base_closure_break_default2_alt3.nit:39)
+`------------------- - - -
--- /dev/null
+alt/base_closure_break_default2_alt4.nit:25,5--12: Error: cannot 'continue', only 'break'.
--- /dev/null
+alt/base_closure_break_default2_alt5.nit:26,5--15: Error: cannot 'continue', only 'break'.
--- /dev/null
+alt/base_closure_break_default2_alt6.nit:27,5--9: Error: break with a value required in this block.
--- /dev/null
+0
+1
+2
+0
+1
+1
+0
--- /dev/null
+alt/base_closure_break_default2_alt8.nit:29,11--13: Type error: expected Int, got Char
--- /dev/null
+alt/base_closure_break_default2_alt9.nit:21,3--12: Control error: Reached end of break block (a 'break' with a value was expected).
--- /dev/null
+0
+1
+2
+0
+1
+0
--- /dev/null
+alt/base_closure_break_default_alt2.nit:23,5--12: Error: Return with value in a procedure.
--- /dev/null
+0
+1
+2
+0
+1
+Aborted (alt/base_closure_break_default_alt3.nit:24)
+,---- Stack trace -- - - -
+| base_closure_break_default_alt3::A::foo (alt/base_closure_break_default_alt3.nit:20)
+| base_closure_break_default_alt3::Sys::(kernel::Sys::main) (alt/base_closure_break_default_alt3.nit:38)
+`------------------- - - -
--- /dev/null
+alt/base_closure_break_default_alt4.nit:25,5--12: Error: cannot 'continue', only 'break'.
--- /dev/null
+alt/base_closure_break_default_alt5.nit:26,5--15: Error: cannot 'continue', only 'break'.
--- /dev/null
+0
+1
+2
+0
+1
+0
--- /dev/null
+alt/base_closure_break_default_alt7.nit:28,5--11: Error: break without value required in this block.