Skip to content

Commit

Permalink
Properly scope local let in trait default implementations
Browse files Browse the repository at this point in the history
When a trait is applied to a type, we copy over the method body
to the new type and as part of this scope everything. This works
fine for `var` which can be redefined at will. Let is a different
story. Given that we already scoped and defined our let, when we go
to do this on the actual type, we end up with an error that we are
redefining it. What we want to be doing is to set local to undefined
and allow them to be set to defined when the expression type checking
happens in the new type.

Closes ponylang#684
  • Loading branch information
SeanTAllen committed Apr 4, 2016
1 parent 8fb58b4 commit b5f180d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions minimal-cases/issue-684/684.pony
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait T
fun foo() =>
let x: U32 = 0

class Baz is T
class Bar is T

actor Main
new create(env: Env) => None
Binary file added minimal-cases/issue-684/issue-684
Binary file not shown.
7 changes: 7 additions & 0 deletions src/libponyc/pass/traits.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,13 @@ static ast_result_t rescope(ast_t** astp, pass_opt_t* options)

case TK_LET:
case TK_VAR:
{
ast_t* scope = ast_parent(ast);
ast_t* id = ast_child(ast);
ast_set(scope, ast_name(id), id, SYM_UNDEFINED);
break;
}

case TK_MATCH_CAPTURE:
{
ast_t* scope = ast_parent(ast);
Expand Down

0 comments on commit b5f180d

Please sign in to comment.