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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2799973003: Check const constructors. (Closed)
Patch Set: Created 3 years, 8 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 | pkg/front_end/lib/src/fasta/source/diet_listener.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/kernel/body_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index bb233f93bc698e6fa67f5f30ff44988870734a8b..2227ee252fc51eba6127c349b442eedd12c9782a 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -577,7 +577,9 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
if (receiver is FastaAccessor) {
- if (constantExpressionRequired && !isIdentical(receiver)) {
+ if (constantExpressionRequired &&
+ !isIdentical(receiver) &&
+ !receiver.isInitializer) {
Paul Berry 2017/04/07 15:59:19 It looks like isInitializer isn't defined on Fasta
ahe 2017/04/07 18:11:15 That part got included in CL 2800083002 by acciden
addCompileTimeError(charOffset, "Not a constant expression.");
}
return receiver.doInvocation(charOffset, arguments);
@@ -724,13 +726,18 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
String name, Arguments arguments, int charOffset,
{bool isSuper: false, isGetter: false, isSetter: false}) {
String errorName = isSuper ? "super.$name" : name;
+ String message;
if (isGetter) {
- warning("Getter not found: '$errorName'.", charOffset);
+ message = "Getter not found: '$errorName'.";
} else if (isSetter) {
- warning("Setter not found: '$errorName'.", charOffset);
+ message = "Setter not found: '$errorName'.";
} else {
- warning("Method not found: '$errorName'.", charOffset);
+ message = "Method not found: '$errorName'.";
}
+ if (constantExpressionRequired) {
+ return buildCompileTimeError(message, charOffset);
+ }
+ warning(message, charOffset);
Constructor constructor =
coreTypes.getClass("dart:core", "NoSuchMethodError").constructors.first;
return new Throw(new ConstructorInvocation(
@@ -828,17 +835,27 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
return new UnresolvedAccessor(this, n, charOffset);
}
} else if (builder.isTypeDeclaration) {
- if (constantExpressionRequired && builder.isTypeVariable) {
+ if (constantExpressionRequired &&
+ builder.isTypeVariable &&
+ !member.isConstructor) {
addCompileTimeError(charOffset, "Not a constant expression.");
}
return builder;
} else if (builder.isLocal) {
- if (constantExpressionRequired && !builder.isConst) {
+ if (constantExpressionRequired &&
+ !builder.isConst &&
+ !member.isConstructor) {
addCompileTimeError(charOffset, "Not a constant expression.");
}
return new VariableAccessor(this, charOffset, builder.target);
} else if (builder.isInstanceMember) {
- if (constantExpressionRequired) {
+ if (constantExpressionRequired &&
+ !inInitializer &&
+ // TODO(ahe): This is a hack because Fasta sets up the scope
+ // "this.field" parameters according to old semantics. Under the new
+ // semantics, such parameters introduces a new parameter with that
+ // name that should be resolved here.
+ !member.isConstructor) {
addCompileTimeError(charOffset, "Not a constant expression.");
}
return new ThisPropertyAccessor(
@@ -1371,7 +1388,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
warningNotError(
"'${beginToken.lexeme}' isn't a type.", beginToken.charOffset);
push(const DynamicType());
- } else if (name is TypeVariableBuilder) {
+ } else if (name is TypeVariableBuilder && !member.isConstructor) {
if (constantExpressionRequired) {
addCompileTimeError(
beginToken.charOffset, "Not a constant expression.");
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/source/diet_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698