Branch: refs/heads/main
Revision: f20de09
Author: bradcray
Link: Unavailable
Log Message:
Merge pull request #18869 from bradcray/try-stmts-only
Make try
statements accept more statement kinds and not arbitrary expressions
[reviewed by @dlongnecke-cray]
In #18859, @bmcdonald3 pointed out some strange behavior where a loop suddenly
generated an error when a try!
was applied to it. It turns out that this is because
the try!
grammar production accepted a general expr
at the statement level,
causing the loop to be interpreted as a loop expression rather than a loop statement.
It seems to me that a statement-level try
or try!
should only be able to be applied
to statements and that an expression-level one should be applied to expressions.
Moreover, in digging into this a bit, it turns out that the only statement-level statements
that try
and try!
can be applied to are the family of assignment statements. So here,
I split the stmt
production into what I called "executable" statements vs. non- (where
that's probably not the best adjective, but...) as a means of indicating which family of
statements seemed (to me anyway) to be ones that try
could be applied to. Checking
the spec to see how we described the syntax of try
and try!
, I'm finding that the
spec doesn't even make an attempt at giving the syntax productions for these, which is...
disappointing, but not something I'm trying to fix here. I've opened issue #18938 to
continue to kick around the question of whether where I've left things is appropriate as
a placeholder for that effort.
Resolves #18859.
Modified Files:
A test/errhandling/stmtVsExpr.chpl
A test/errhandling/stmtVsExpr.good
A test/errhandling/tryBangNonBlockStmt.chpl
A test/errhandling/tryBangNonBlockStmt.good
M compiler/include/bison-chapel.h
M compiler/next/lib/parsing/bison-chpl-lib.cpp
M compiler/next/lib/parsing/chpl.ypp
M compiler/parser/bison-chapel.cpp
M compiler/parser/chapel.ypp
Compare: https://github.com/chapel-lang/chapel/compare/17e106cf143a...f20de0922fac