Ticket #85 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

LetStatement should require a block

Reported by: lth Assigned to: jeffdyer
Type: defect Priority: major
Milestone: M1 Component: Proposals
Version: 4 Keywords:
Cc:

Description

I'm fairly sure this is wrong:

>> let (x = 10);
>>

The statement is neither a let expression (no experssion in the body) nor a let statement (braces required) nor a let-is-the-new-var statement (parens should not be valid).

Attachments

Change History

Changed 2 years ago by jeffdyer

The current grammar allows it. It is a LetStatement? with an EmptyStatement? as its body. Here's to rule:

	LetStatement
		let  (  LetBindingList  )  Substatement

It mirrors the syntax of other statements with heads. e.g.

        WithStatement
	        with  TypedExpression  Substatement
	TypedExpression
		ParenListExpression
		ParenListExpression  :  NullableTypeExpression

True, it leads to the meaningless statement you show, but it allows useful shorthands such as we are promoting with braceless function definitions, and is consistent with the syntax of other statements.

I think it's NAB.

Changed 2 years ago by lth

  • summary changed from Parser bug to Should let-statement require a block?

Your point is well taken.

Let me argue :-)

The issue came up because I had converted a let-expression into what I intended to be a let-is-the-new-var statement, but instead it had become a let-statement. I don't think this kind of bug will be a big deal in practice, though.

Other let-scoped binding forms in the language (switch type; catch) require braces around the statements in whose scope the binding has effect. WithStatement et al do not bind anything. This is probably my most important argument.

The original proposal requires a "Block" for the SubStatement (to syntactically disambiguate it for the reader).

I can't see an actual ambiguity, though, certainly not one that matters.

Changed 2 years ago by jeffdyer

  • summary changed from Should let-statement require a block? to LetStatement should require a block?

Okay, you've convinced me with your "most important argument". Statements that introduce bindings all have bodies enclosed in braces. So your test case has neither a valid LetStatement? nor a LetExpression?.

Just to be clear, the following is a legal LetExpression? inside of an ExpressionStatement?:

   let (x=10) y = x;

Changed 2 years ago by jeffdyer

  • summary changed from LetStatement should require a block? to LetStatement should require a block

Changed 2 years ago by jeffdyer

  • status changed from new to closed
  • resolution set to fixed

fixed: committed revision e62c2ddc0afc6b3e15c6f5e439bd3b3250328de9

Note: See TracTickets for help on using tickets.