"IF" after statement = Syntax Error?

Well this is weird - seems that “if” statement following another statement on the same line causes “Syntax Error. (compile error &h02)”. Example:

dice = rnd(6): if dice < 2 then
    ? "You get nothing"
end if

I don’t see any other statement behaving like that (else, end if, while, end while, for, end for etc don’t seem to mind sharing a line with buddies). Probably a compiler issue?

But why would i want to do such a strange thing, you may ask? I have a use case, i want to profile my code and i can do this simply by inserting in the beginning of every line a single call to a function that collects the stats. That works no matter what the rest of the line, even if empty or commented out… bar IF. It’s way easy to “instrument” and remove this in text editor using rectangle-block select. Here is how that looks like:

sub _profile(next_line, tm, acc):
    t = acc[next_line-1]
    if t = invalid then t = 0
    acc[next_line-1] = t + tm.TotalMilliseconds()
    tm.mark()
end sub

function xml_parse(xml as string):
_ = []: ti = createobject("roTimespan")
_profile(LINE_NUM, ti, _):    leafs = []
_profile(LINE_NUM, ti, _):    tags = xml.tokenize("<")
_profile(LINE_NUM, ti, _):    startN = 0
_profile(LINE_NUM, ti, _):    if tags.count() > 0 and left(xml, 1) <> "<"     'line 183
_profile(LINE_NUM, ti, _):        startN = 1
_profile(LINE_NUM, ti, _):        if tags[0].trim() <> "":                    'line 185
_profile(LINE_NUM, ti, _):            leafs.push(tags[0])
_profile(LINE_NUM, ti, _):        end if
_profile(LINE_NUM, ti, _):    end if
...

And here is how compiler grumbles:

*** ERROR compiling /pkg:/source/something.brs:
Syntax Error. (compile error &h02) in ...8n/pkg:/source/something.brs(183)
Syntax Error. (compile error &h02) in ...8n/pkg:/source/something.brs(185)