Skip to content
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

Fix nested tuple access regression introduced by #3304 #3381

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/libponyc/pass/refer.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ bool refer_dot(pass_opt_t* opt, ast_t* ast)
{
// check multi_dot reference if it's not a function call
// only if we had a field consume/reassign
if(!ast_checkflag(ast, AST_FLAG_FCNSM_REASGN)
if(ast_checkflag(ast, AST_FLAG_FCNSM_REASGN)
&& (ast_id(ast_parent(ast)) != TK_CALL)
&& (ast_id(ast_parent(ast)) != TK_QUALIFY))
return refer_multi_dot(opt, ast);
Expand Down Expand Up @@ -1055,20 +1055,20 @@ static bool check_assigned_same_expression(ast_t* ast, const char* name,
return ast_get_child(assign_left, name);
}

static void set_flag_recursive(ast_t* outer, ast_t* inner, uint32_t flag)
static void set_flag_recursive(ast_t* outer, uint32_t flag)
{
pony_assert(outer != NULL);
pony_assert(inner != NULL);

do
{
ast_setflag(inner, flag);
ast_setflag(outer, flag);

if(inner == outer)
break;
ast_t* child = ast_child(outer);

inner = ast_parent(inner);
} while(inner != NULL);
while(child != NULL)
{
set_flag_recursive(child, flag);

child = ast_sibling(child);
}
}

static bool refer_consume(pass_opt_t* opt, ast_t* ast)
Expand Down Expand Up @@ -1152,8 +1152,8 @@ static bool refer_consume(pass_opt_t* opt, ast_t* ast)

consumed_same_expr = true;

// assign flag to full tree from ast to assign_ast
set_flag_recursive(assign_ast, ast, AST_FLAG_FCNSM_REASGN);
// assign flag to assign_ast and all children
set_flag_recursive(assign_ast, AST_FLAG_FCNSM_REASGN);

break;
}
Expand Down
12 changes: 12 additions & 0 deletions test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1072,3 +1072,15 @@ TEST_F(BadPonyTest, AllowAliasForNonEphemeralReturn)

TEST_COMPILE(src);
}

TEST_F(BadPonyTest, AllowNestedTupleAccess)
{
// From issue #3354
const char* src =
"actor Main\n"
" new create(env: Env) =>\n"
" let x = (1, (2, 3))._2._1";

TEST_ERRORS_1(src,
"Cannot look up member _2 on a literal")
}