-
-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent compiler crashes on certain consume
expressions
#3650
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||
## Graceful error handling on `consume` expressions | ||||||||
|
||||||||
The fix ensures | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
* `consume (consume variable).field` results in a graceful compilation error | ||||||||
* `consume f().field` results in similar compilation error as `consume f()` | ||||||||
* Allow `(consume obj).field` expressions | ||||||||
kapilash marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
The following snippet | ||||||||
```pony | ||||||||
kapilash marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
(consume f).b = recover Bar end | ||||||||
``` | ||||||||
must be equivalent to | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
must be equivalent to
|
||||||||
|
||||||||
```pony | ||||||||
let x = consume f | ||||||||
x.b = recover Bar end | ||||||||
``` | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,14 +139,16 @@ static const char* generate_multi_dot_name(ast_t* ast, ast_t** def_found) { | |
|
||
default: | ||
{ | ||
if (def == NULL) | ||
return stringtab(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jemc , this is one change needed in
|
||
pony_assert(0); | ||
} | ||
} | ||
|
||
if(def_found != NULL) | ||
{ | ||
*def_found = def; | ||
|
||
kapilash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if(def == NULL) | ||
return stringtab(""); | ||
} | ||
|
@@ -1166,10 +1168,6 @@ static bool refer_consume(pass_opt_t* opt, ast_t* ast) | |
"can't consume a let or embed field"); | ||
return false; | ||
} | ||
} else if (ast_id(left) == TK_CALL) { | ||
ast_error(opt->check.errors, ast, | ||
"consume expressions must specify a single identifier"); | ||
return false; | ||
} | ||
else | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -696,14 +696,19 @@ static ast_result_t syntax_consume(pass_opt_t* opt, ast_t* ast) | |
{ | ||
case TK_THIS: | ||
case TK_REFERENCE: | ||
case TK_DOT: | ||
return AST_OK; | ||
|
||
case TK_DOT: { | ||
AST_GET_CHILDREN(term, left, right); | ||
if (ast_id(left) != TK_CALL && ast_id(left) != TK_SEQ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I went a bit too defensive and raising errors for known errors. Do you suggest we go a bit more aggressive here? It could mean we will have to do go up and down the ast a bit more. |
||
{ | ||
return AST_OK; | ||
} | ||
kapilash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
default: {} | ||
} | ||
|
||
ast_error(opt->check.errors, term, | ||
"Consume expressions must specify a single identifier"); | ||
"Consume expressions must specify an identifier or field"); | ||
return AST_ERROR; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what is missing from these release notes is an that previously some of these things might have been compiler errors etc before. The fix ensures some things, but what does that mean for the end-user?
Something along the lines of "previously any of X would result in Y that has now been fixed" is an important part of the release notes messaging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rephrased. Can you please check if this sounds better? also I removed one of the points. I notice that 0.38.0 already covered it. (That particular fix was only refactored this time around).