-
Notifications
You must be signed in to change notification settings - Fork 207
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
Initial cut at an NNBD specification #293
Changes from 10 commits
d8f44d0
f7c278f
79e8f58
a9e7eab
eec13c1
1260b58
03cc142
03813d3
5c024e5
2466591
186d675
b5d301e
47016c5
e721716
c2b4c0f
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 |
---|---|---|
|
@@ -832,9 +832,9 @@ \section{Variables} | |
|
||
<declaredIdentifier> ::= <metadata> \COVARIANT{}? <finalConstVarOrType> <identifier> | ||
|
||
<finalConstVarOrType> ::= \FINAL{} <type>? | ||
<finalConstVarOrType> ::= \alt \LATE{}? \FINAL{} <type>? | ||
\alt \CONST{} <type>? | ||
\alt <varOrType> | ||
\alt \LATE{}? <varOrType> | ||
|
||
<varOrType> ::= \VAR{} | ||
\alt <type> | ||
|
@@ -1411,13 +1411,13 @@ \subsection{Formal Parameters} | |
\begin{grammar} | ||
<formalParameterList> ::= `(' `)' | ||
\alt `(' <normalFormalParameters> `,'? `)' | ||
\alt `(' <normalFormalParameters> `,' <optionalFormalParameters> `)' | ||
\alt `(' <optionalFormalParameters> `)' | ||
\alt `(' <normalFormalParameters> `,' <optionalOrNamedFormalParameters> `)' | ||
\alt `(' <optionalOrNamedFormalParameters> `)' | ||
|
||
<normalFormalParameters> ::= \gnewline{} | ||
<normalFormalParameter> (`,' <normalFormalParameter>)* | ||
|
||
<optionalFormalParameters> ::= <optionalPositionalFormalParameters> | ||
<optionalOrNamedFormalParameters> ::= <optionalPositionalFormalParameters> | ||
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. We currently disallow having both optional positional and named parameters. 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. Personally, I'd like to see us allow all four varieties. Whether that happens sooner or later is a separate question, but it makes it much easier to migrate users to a new API if named and optional positional can be mixed, so I'd prefer sooner. 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. It is top of my list for improvements going on 6.5 years now (https://github.com/dart-lang/sdk/issues/7056, sadly only the nr 27 most wanted feature based on 👍 count). 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.
This seems to me raise the same kind of calling convention questions that other combinations raise. class A {
void foo({required int x}) {}
}
class B extends A {
void foo({int x}) {}
}
class C extends A {
void foo([int y], {required int x}) {}
} A call site that looks like I'm not entirely unsympathetic to broadening our calling conventions, but I think that's a separate change that we need to make with full buy in from the various teams. |
||
\alt <namedFormalParameters> | ||
|
||
<optionalPositionalFormalParameters> ::= \gnewline{} | ||
|
@@ -1485,8 +1485,8 @@ \subsubsection{Optional Formals} | |
\begin{grammar} | ||
<defaultFormalParameter> ::= <normalFormalParameter> (`=' <expression>)? | ||
|
||
<defaultNamedParameter> ::= <normalFormalParameter> (`=' <expression>)? | ||
\alt <normalFormalParameter> ( `:' <expression>)? | ||
<defaultNamedParameter> ::= \REQUIRED{}? <normalFormalParameter> (`=' <expression>)? | ||
\alt \REQUIRED{}? <normalFormalParameter> ( `:' <expression>)? | ||
leafpetersen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
\end{grammar} | ||
|
||
The form \syntax{<normalFormalParameter> `:' <expression>} | ||
|
@@ -1853,9 +1853,12 @@ \section{Classes} | |
\alt (\EXTERNAL{} \STATIC{}?)? <setterSignature> | ||
\alt \EXTERNAL{}? <operatorSignature> | ||
\alt (\EXTERNAL{} \STATIC{}?)? <functionSignature> | ||
\alt \STATIC{} (\FINAL{} | \CONST{}) <type>? <staticFinalDeclarationList> | ||
\alt \FINAL{} <type>? <initializedIdentifierList> | ||
\alt (\STATIC{} | \COVARIANT{})? (\VAR{} | <type>) <initializedIdentifierList> | ||
\alt \STATIC{} \LATE{}? \FINAL{} <type>? <staticFinalDeclarationList> | ||
\alt \STATIC{} \LATE{}? (\VAR{} | <type>) <initializedIdentifierList> | ||
\alt \STATIC{} \CONST{) <type>? <staticFinalDeclarationList> | ||
\alt \COVARIANT{} \LATE{}? (\VAR{} | <type>) <initializedIdentifierList> | ||
\alt \LATE{}? \FINAL{} <type>? <initializedIdentifierList> | ||
\alt \LATE{}? (\VAR{} | <type>) <initializedIdentifierList> | ||
|
||
<staticFinalDeclarationList> ::= \gnewline{} | ||
<staticFinalDeclaration> (`,' <staticFinalDeclaration>)* | ||
|
@@ -3007,7 +3010,7 @@ \subsubsection{Generative Constructors} | |
\alt <assertion> | ||
|
||
<fieldInitializer> ::= \gnewline{} | ||
(\THIS{} `.')? <identifier> `=' <conditionalExpression> <cascadeSection>* | ||
(\THIS{} `.')? <identifier> `=' <conditionalExpression> <cascadeSequence>? | ||
\end{grammar} | ||
|
||
\LMHash{}% | ||
|
@@ -5888,7 +5891,7 @@ \section{Expressions} | |
|
||
\begin{grammar} | ||
<expression> ::= <assignableExpression> <assignmentOperator> <expression> | ||
\alt <conditionalExpression> <cascadeSection>* | ||
\alt <conditionalExpression> <cascadeSequence>? | ||
\alt <throwExpression> | ||
|
||
<expressionWithoutCascade> ::= \gnewline{} | ||
|
@@ -9485,10 +9488,14 @@ \subsubsection{Cascaded Invocations} | |
where $e$ is an expression and \metavar{suffix} is a sequence of operator, method, getter or setter invocations. | ||
|
||
\begin{grammar} | ||
<cascadeSection> ::= `..' (<cascadeSelector> <argumentPart>*) | ||
<cascadeSequence> ::= (`?..' \alt `..') <cascadeSection> <cascadeSectionContinuation>* | ||
|
||
<cascadeSection> ::= (<cascadeSelector> <argumentPart>*) | ||
\gnewline{} (<assignableSelector> <argumentPart>*)* | ||
\gnewline{} (<assignmentOperator> <expressionWithoutCascade>)? | ||
|
||
<cascadeSectionContinuation> ::= `..' <cascadeSection> | ||
|
||
<cascadeSelector> ::= `[' <expression> `]' | ||
\alt <identifier> | ||
|
||
|
@@ -11502,6 +11509,9 @@ \subsection{Assignable Expressions} | |
|
||
<assignableSelector> ::= <unconditionalAssignableSelector> | ||
\alt `?.' <identifier> | ||
\alt `?[' <expression> `]' | ||
\alt `!' | ||
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. I don't think Maybe we can use a grammar like: <cascadeSequence> ::= (`?..' \alt `..') <cascadeSection> (`..' <cascadeSection>)*
<cascadeSection> ::= <cascadeSelector> (<cascadeAssignment> | <selector>* (<assignableSelector> <cascadeAssignment>)?)
<selector> ::= `!'
\alt <argumentPart>
\alt <assignableSelector>
<assignableSelector> ::= (`?.' \alt `.') <identifier>
\alt `?.'? `[' expression `]'
<cascadeAssignment> ::= <assignmentOperator> <expressionWithoutCascade> (should we allow 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.
If you do this, then you can't write
How does this derive? I don't see how 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. If you change <selector> ::= `!'
\alt <argumentPart>
\alt <assignableSelector> and either
(from <assignableeExpression> ::= <primary> <assignableSelectorPart>
\alt \SUPER{} <unconditionalAssignableSelector>
\alt <constructorInvocation> <assignableSelectorPart>
\alt <identifier>
<assignableSelectorPart> ::= <selector>* <assignableSelector> then you can derive You are correct that just changing About <cascadeSection> ::= `..' (<cascadeSelector> <argumentPart>*)
\gnewline{} (<assignableSelector> <argumentPart>*)*
\gnewline{} (<assignmentOperator> <expressionWithoutCascade>)? and with:
you can derive The problem is that The code is rejected by our tools anyway, even though it satisfies the grammar. It is then treated as equivalent to main() {
42..toString() = 4;
} gives the CFE error:
and the analyzer error:
(The second error is spurious—there is no variable of type string in the program—which suggests that the analyzer isn't entirely comfortable with this misuse of syntax). 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. @lrhn If I do as you suggest, then I don't think you can have
I think this cascade parses with my grammar as:
How does it parse with yours? 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. Let's pick the first grammar I proposed: <cascadeSequence> ::= (`?..' \alt `..') <cascadeSection> (`..' <cascadeSection>)*
<cascadeSection> ::= <cascadeSelector> (<cascadeAssignment> | <selector>* (<assignableSelector> <cascadeAssignment>)?)
<selector> ::= `!' /// <--- the ! is here
\alt <argumentPart>
\alt <assignableSelector>
<assignableSelector> ::= (`?.' \alt `.') <identifier>
\alt `?.'? `[' expression `]'
<cascadeAssignment> ::= <assignmentOperator> <expressionWithoutCascade> Then the cascade section of a...foo()!.bar = 3 parses as
We only want the actually assignable selectors to be assignable, and 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. Okay, I've taken your suggestion, PTAL. |
||
|
||
\end{grammar} | ||
|
||
\LMHash{}% | ||
|
@@ -14121,15 +14131,18 @@ \subsection{Static Types} | |
} | ||
|
||
\begin{grammar} | ||
<type> ::= <functionTypeTails> | ||
\alt <typeNotFunction> <functionTypeTails> | ||
|
||
<type> ::= <functionType> `?'? | ||
\alt <typeNotFunction> | ||
|
||
<typeNotFunction> ::= <typeNotVoidNotFunction> | ||
\alt \VOID{} | ||
<typeNotVoid> ::= <functionType> `?'? | ||
\alt <typeNotVoidNotFunction> | ||
|
||
<typeNotVoidNotFunction> ::= <typeName> <typeArguments>? | ||
\alt \FUNCTION{} | ||
<typeNotFunction> ::= \VOID{} | ||
\alt <typeNotVoidNotFunction> | ||
|
||
<typeNotVoidNotFunction> ::= <typeName> <typeArguments>? `?'? | ||
\alt \FUNCTION{} `?'? | ||
leafpetersen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<typeName> ::= <typeIdentifier> (`.' <typeIdentifier>)? | ||
|
||
|
@@ -14140,13 +14153,10 @@ \subsection{Static Types} | |
<typeNotVoidNotFunctionList> ::= \gnewline{} | ||
<typeNotVoidNotFunction> (`,' <typeNotVoidNotFunction>)* | ||
|
||
<typeNotVoid> ::= <functionType> | ||
\alt <typeNotVoidNotFunction> | ||
|
||
<functionType> ::= <functionTypeTails> | ||
\alt <typeNotFunction> <functionTypeTails> | ||
|
||
<functionTypeTails> ::= <functionTypeTail> <functionTypeTails> | ||
<functionTypeTails> ::= <functionTypeTail> `?'? <functionTypeTails> | ||
\alt <functionTypeTail> | ||
|
||
<functionTypeTail> ::= \FUNCTION{} <typeParameters>? <parameterTypeList> | ||
|
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
late
will be fine as a built-in identifier. After allstatic
works as a built-in identifier.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.
@bwilkerson was advocating for this to be a keyword on the grounds that it makes error recovery much more robust. I don't have strong feelings about this - I see arguments on both sides. Taking away variable names from programmers is painful for them (and for us), but making error recovery less robust is a tax on everything.