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

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

Issue 2777533002: Report compile-time error on invalid constructors. (Closed)
Patch Set: Update status files. Created 3 years, 9 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/kernel/kernel_target.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 c8c184fa1388d9982998daa415a5941f87f6daa2..4f93069d9642525c687d9e003229882c8b1c3244 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -1745,52 +1745,55 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
String name = pop();
List<DartType> typeArguments = pop();
var type = pop();
- constantExpressionRequired = pop();
-
- if (arguments == null) {
- push(buildCompileTimeError("No arguments.", nameToken.charOffset));
- return;
- }
+ bool savedConstantExpressionRequired = pop();
+ () {
+ if (arguments == null) {
+ push(buildCompileTimeError("No arguments.", nameToken.charOffset));
+ return;
+ }
- if (typeArguments != null) {
- assert(arguments.types.isEmpty);
- arguments.types.addAll(typeArguments);
- }
+ if (typeArguments != null) {
+ assert(arguments.types.isEmpty);
+ arguments.types.addAll(typeArguments);
+ }
- String errorName;
- if (type is ClassBuilder) {
- Builder b = type.findConstructorOrFactory(name);
- Member target;
- if (b == null) {
- // Not found. Reported below.
- } else if (b.isConstructor) {
- if (type.isAbstract) {
- // TODO(ahe): Generate abstract instantiation error.
- } else {
- target = b.target;
+ String errorName;
+ if (type is ClassBuilder) {
+ Builder b = type.findConstructorOrFactory(name);
+ Member target;
+ if (b == null) {
+ // Not found. Reported below.
+ } else if (b.isConstructor) {
+ if (type.isAbstract) {
+ // TODO(ahe): Generate abstract instantiation error.
+ } else {
+ target = b.target;
+ }
+ } else if (b.isFactory) {
+ target = getRedirectionTarget(b.target);
+ if (target == null) {
+ push(buildCompileTimeError(
+ "Cyclic definition of factory '${name}'.",
+ nameToken.charOffset));
+ return;
+ }
}
- } else if (b.isFactory) {
- target = getRedirectionTarget(b.target);
- if (target == null) {
- push(buildCompileTimeError(
- "Cyclic definition of factory '${name}'.", nameToken.charOffset));
+ if (target is Constructor ||
+ (target is Procedure && target.kind == ProcedureKind.Factory)) {
+ push(buildStaticInvocation(target, arguments,
+ isConst: optional("const", token),
+ charOffset: nameToken.charOffset));
return;
+ } else {
+ errorName = debugName(type.name, name);
}
- }
- if (target is Constructor ||
- (target is Procedure && target.kind == ProcedureKind.Factory)) {
- push(buildStaticInvocation(target, arguments,
- isConst: optional("const", token),
- charOffset: nameToken.charOffset));
- return;
} else {
- errorName = debugName(type.name, name);
+ errorName = debugName(getNodeName(type), name);
}
- } else {
- errorName = debugName(getNodeName(type), name);
- }
- errorName ??= name;
- push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset));
+ errorName ??= name;
+ push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset));
+ }();
+ constantExpressionRequired = savedConstantExpressionRequired;
}
@override
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_target.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698