added footgun warning when calling labels as subroutine

This commit is contained in:
Irmen de Jong
2025-03-04 22:14:21 +01:00
parent 582a70b046
commit 40423911ef
3 changed files with 9 additions and 4 deletions
@@ -1522,8 +1522,11 @@ internal class AstChecker(private val program: Program,
}
}
if(target is Label && args.isNotEmpty())
errors.err("cannot use arguments when calling a label", position)
if (target is Label) {
errors.warn("\uD83D\uDCA3 footgun: calling label as subroutine (JSR) is tricky", position)
if (args.isNotEmpty())
errors.err("cannot use arguments when calling a label", position)
}
if(target is Subroutine) {
if(target.isAsmSubroutine) {
+3 -2
View File
@@ -63,10 +63,11 @@ Subroutine
Label
This is a named position in your code where you can jump to from another place.
You can jump to it with a jump statement elsewhere. It is also possible to use a
subroutine call to a label (but without parameters and return value).
A label is an identifier followed by a colon ``:``. It's ok to put the next statement on
the same line, immediately after the label.
You can jump to it with a goto statement. It is also possible to use a
subroutine call to a label (but without parameters and return value), however 🦶🔫 footgun warning:
doing that is tricky because it makes for weird control flow and interferes with defers.
Scope
Also known as 'namespace', this is a named box around the symbols defined in it.
+1
View File
@@ -3,6 +3,7 @@
main {
sub start() {
defer txt.print("defer\n")
txt.print("1\n")
label()
txt.print("2\n")