-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sem: keep shape of array constructors in typed AST (#1340)
## Summary Explicit indices in array constructors now stay in the AST after typing. Since macros are able to observe this, this change is a **breaking change**. ## Details Keeping the explicit indices is also necessary for being able to retype the AST after it was typed once (without the index, array constructors for arrays not starting at zero would have a different type afterwards). Instead of dropping the explicit index together with the parent `nkExprColonExpr` node, both are kept by `semArrayConstr`, and then later discarded by `semfold` (during constant evaluation) and `transf`, where they are no longer needed.
- Loading branch information
Showing
4 changed files
with
48 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
discard """ | ||
description: ''' | ||
Ensure that the shape of literal array construction expresions is | ||
preserved in typed AST | ||
''' | ||
action: compile | ||
""" | ||
|
||
import std/macros | ||
|
||
macro m(x: typed) = | ||
doAssert treeRepr(x) == """Bracket | ||
ExprColonExpr | ||
IntLit 1 | ||
StrLit "a" | ||
StrLit "b" | ||
ExprColonExpr | ||
IntLit 3 | ||
StrLit "c"""" | ||
|
||
m([1: "a", "b", 3: "c"]) |