From 3c1acff34c1f88b58a1e1593c49fca342f0346bb Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sat, 7 Sep 2024 23:02:29 +0200 Subject: [PATCH] tests/class: Make into class return rules testing test --- tests/class_return_rules.fl | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/class_return_rules.fl diff --git a/tests/class_return_rules.fl b/tests/class_return_rules.fl new file mode 100644 index 0000000..ad746e6 --- /dev/null +++ b/tests/class_return_rules.fl @@ -0,0 +1,45 @@ +# Tests related to when we can and can't return from classes. +# Again, similar to assignemnt + +class Illegal { + return none +} + +class Illegal2 { + { + return none + } +} + +class Illegal3 { + { + return 69 + } +} + +class Legal { +} + +assert Legal() != none + +class LegalExplicitReturn { + a = 69 + a = 420 + return +} + +# TODO There's currently a pretty sizable issue with shadowing and class members which means I can't name this 'a' too. +# A proper solution would be to introduce a 'let' keyword but eeeeh... +# Although if the plan is anyway to use Bob for config files and the variables are already declared in an import, this might even be a good thing. + +b = LegalExplicitReturn() +assert b.a == 420 + +class LegalControlFlowInterruption { + a = 69 + return + a = 420 +} + +b = LegalControlFlowInterruption() +assert b.a == 69