Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Unified Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 26370004: Emit a compile-time error when using default values in function typed parameter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart
diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
index 369405f20afba3ca1607be1657893ed00069e5aa..ed9fff1d03639d4b4c40afc800d74df0ddaf906a 100644
--- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -3473,7 +3473,7 @@ class TypedefResolverVisitor extends TypeDefinitionVisitor {
FunctionSignature signature = SignatureResolver.analyze(
compiler, node.formals, node.returnType, element,
- defaultValuesAllowed: false);
+ defaultValuesError: MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT);
element.functionSignature = signature;
scope = new MethodScope(scope, element);
@@ -4108,7 +4108,7 @@ class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> {
*/
class SignatureResolver extends CommonResolverVisitor<Element> {
final Element enclosingElement;
- final bool defaultValuesAllowed;
+ final MessageKind defaultValuesError;
Link<Element> optionalParameters = const Link<Element>();
int optionalParameterCount = 0;
bool isOptionalParameter = false;
@@ -4117,9 +4117,11 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
SignatureResolver(Compiler compiler,
this.enclosingElement,
- {this.defaultValuesAllowed: true})
+ {this.defaultValuesError})
: super(compiler);
+ bool get defaultValuesAllowed => defaultValuesError == null;
+
Element visitNodeList(NodeList node) {
// This must be a list of optional arguments.
String value = node.beginToken.stringValue;
@@ -4248,7 +4250,7 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
}
Node defaultValue = node.arguments.head;
if (!defaultValuesAllowed) {
- error(defaultValue, MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT);
+ error(defaultValue, defaultValuesError);
}
// Visit the value. The compile time constant handler will
// make sure it's a compile time constant.
@@ -4257,6 +4259,7 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
}
Element visitFunctionExpression(FunctionExpression node) {
+ // This is a function typed parameter.
Modifiers modifiers = currentDefinitions.modifiers;
if (modifiers.isFinal()) {
compiler.reportError(modifiers,
@@ -4265,9 +4268,14 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
if (modifiers.isVar()) {
compiler.reportError(modifiers, MessageKind.VAR_FUNCTION_TYPE_PARAMETER);
}
- // This is a function typed parameter.
- // TODO(ahe): Resolve the function type.
- return visit(node.name);
+
+ Element variable = visit(node.name);
+ SignatureResolver.analyze(compiler, node.parameters, node.returnType,
+ variable,
+ defaultValuesError: MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT);
+ // TODO(ahe): Resolve and record the function type in the correct
+ // [TreeElements].
+ return variable;
}
LinkBuilder<Element> analyzeNodes(Link<Node> link) {
@@ -4294,9 +4302,9 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
NodeList formalParameters,
Node returnNode,
Element element,
- {bool defaultValuesAllowed: true}) {
+ {MessageKind defaultValuesError}) {
SignatureResolver visitor = new SignatureResolver(compiler, element,
- defaultValuesAllowed: defaultValuesAllowed);
+ defaultValuesError: defaultValuesError);
Link<Element> parameters = const Link<Element>();
int requiredParameterCount = 0;
if (formalParameters == null) {
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698