-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Named instantiation of template arguments (#2546)
Implementation of named template arguments as described in #2340. I added a new syntax node (TemplateArgument), and a cover grammar for this node: `<Expression> ('=' <Expression>)?` Rather than ExpressionNode, the type of a template argument is now `TemplateArgumentNode`. If the `=` is parsed, we assert in the parser that the first Expression must be a "bare identifier" (i.e. a TypeReference with `target: Identifier`) and unwrap the identifier to produce a clean AST with `name?: Identifier Template arguments are evaluated in the order that they were declared, not in the order they are specified in the instantiation. The new template argument checker _replaces_ the previous one, and it performs normalization of argument order and typechecking of template arguments all in one pass. TODO: - [x] Review templates across core libraries to ensure that template arguments have good names. - [x] Documentation of new behavior in website. - [x] Semantic/tmlanguage colorization of tokens. - [x] Validate that the AST printer produces the correct text for the new template argument nodes and that the output is well-formatted. - [x] Completion of template argument names in argument position. - [x] Hover context on template argument names in instantiation. Closes #2340 --------- Co-authored-by: Will Temple <[email protected]> Co-authored-by: Mark Cowlishaw <[email protected]> Co-authored-by: Timothee Guerin <[email protected]>
- Loading branch information
1 parent
aae7166
commit cb92f49
Showing
15 changed files
with
865 additions
and
112 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@typespec/compiler/compiler-named-template-params_2023-10-10-02-34.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@typespec/compiler", | ||
"comment": "Added support for named template arguments (#2340)", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@typespec/compiler" | ||
} |
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
Oops, something went wrong.