Skip to content

Parse error in if-else #2697

@VMatthijs

Description

@VMatthijs

Summary:

Conditional control flow constructs have strange parsing behaviour with block structure.

Description:

For an if-then-else statement, it seems that we are required to specify a block statement for the then-clause. Arbitrary statements seem disallowed.

Reproducible Steps:

Try to compile

model {
    if (1)
      print(5);
    else
      print(4);
}

Current Output:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Variable "else" does not exist.
error in 'stan/src/test/test-models/good/if-else-blockless.stan' at line 4, column 9

 2:     if (1)
 3:       print(5);
 4:     else
            ^
 5:       print(4);

Expected Output:

I would expect this to parse just fine.

Current Version:

v2.18.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions