mirror of
https://github.com/irmen/prog8.git
synced 2026-04-20 11:17:01 +00:00
added footgun warning when calling labels as subroutine
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
defer txt.print("defer\n")
|
||||
txt.print("1\n")
|
||||
label()
|
||||
txt.print("2\n")
|
||||
|
||||
Reference in New Issue
Block a user