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

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

Issue 2781493002: Throw AbstractClassInstantiationError on abstract classes. (Closed)
Patch Set: Update co19 status. 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/loader.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 11d7ae82613d9e57f84dadcf87effa8a43d52b98..4f8e43e44d765f31c0698e5bd6d8b60d9eb84f39 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -1699,6 +1699,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
{bool isConst: false, int charOffset: -1}) {
List<TypeParameter> typeParameters = target.function.typeParameters;
if (target is Constructor) {
+ assert(!target.enclosingClass.isAbstract);
typeParameters = target.enclosingClass.typeParameters;
}
if (!checkArguments(target.function, arguments, typeParameters)) {
@@ -1792,7 +1793,11 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
// Not found. Reported below.
} else if (b.isConstructor) {
if (type.isAbstract) {
- // TODO(ahe): Generate abstract instantiation error.
+ push(evaluateArgumentsBefore(
+ arguments,
+ buildAbstractClassInstantiationError(
+ type.name, nameToken.charOffset)));
+ return;
} else {
target = b.target;
}
@@ -2369,8 +2374,16 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
String message = formatUnexpected(uri, charOffset, error);
Builder constructor = library.loader.getCompileTimeError();
return new Throw(buildStaticInvocation(constructor.target,
- new Arguments(<Expression>[new StringLiteral(message)]),
- isConst: false)); // TODO(ahe): Make this const.
+ new Arguments(<Expression>[new StringLiteral(message)])));
+ }
+
+ Expression buildAbstractClassInstantiationError(String className,
+ [int charOffset = -1]) {
+ warning("The class '$className' is abstract and can't be instantiated.",
+ charOffset);
+ Builder constructor = library.loader.getAbstractClassInstantiationError();
+ return new Throw(buildStaticInvocation(constructor.target,
+ new Arguments(<Expression>[new StringLiteral(className)])));
}
Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) {
@@ -2424,6 +2437,22 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
}
+ Expression evaluateArgumentsBefore(
+ Arguments arguments, Expression expression) {
+ if (arguments == null) return expression;
+ List<Expression> expressions =
+ new List<Expression>.from(arguments.positional);
+ for (NamedExpression named in arguments.named) {
+ expressions.add(named.value);
+ }
+ for (Expression argument in expressions.reversed) {
+ expression = new Let(
+ new VariableDeclaration.forValue(argument, isFinal: true),
+ expression);
+ }
+ return expression;
+ }
+
@override
void debugEvent(String name) {
// printEvent(name);
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698