JoeStrout/miniscript

Using `break` inside if-block results in "strange" error message

Closed this issue · 3 comments

I wanted to try out what happens if I use break inside an if:

if 1 then
    break
end if

I get this error:

Compiler Error: unmatched block opener [line 6]

For me as a user it does not make much sense. I would expect something like "You can't use a break inside an if". Or simply for it to be ignored.

I don't see this as a serious error, and it's an edge case, but still surprising.

Well, you can use a break inside an if, of course, provided the if is inside a loop.

But I agree the error message when it's not is poor, and could be improved. Good find!

In addition, if you type break by itself at the REPL, you get the "more input needed" prompt, even though I have no idea what more it is expecting. These may be two manifestations of the same thing.

Not sure how related it is, but let's also fix this one:

]if true then for i in [1,2,3]
Compiler Error: 'end if' without matching 'if' [line 1]
]