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

Side by Side 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, 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/loader.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import '../parser/parser.dart' show FormalParameterType, optional; 7 import '../parser/parser.dart' show FormalParameterType, optional;
8 8
9 import '../parser/error_kind.dart' show ErrorKind; 9 import '../parser/error_kind.dart' show ErrorKind;
10 10
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 push(type); 1692 push(type);
1693 push(typeArguments ?? NullValue.TypeArguments); 1693 push(typeArguments ?? NullValue.TypeArguments);
1694 push(name); 1694 push(name);
1695 } 1695 }
1696 1696
1697 @override 1697 @override
1698 Expression buildStaticInvocation(Member target, Arguments arguments, 1698 Expression buildStaticInvocation(Member target, Arguments arguments,
1699 {bool isConst: false, int charOffset: -1}) { 1699 {bool isConst: false, int charOffset: -1}) {
1700 List<TypeParameter> typeParameters = target.function.typeParameters; 1700 List<TypeParameter> typeParameters = target.function.typeParameters;
1701 if (target is Constructor) { 1701 if (target is Constructor) {
1702 assert(!target.enclosingClass.isAbstract);
1702 typeParameters = target.enclosingClass.typeParameters; 1703 typeParameters = target.enclosingClass.typeParameters;
1703 } 1704 }
1704 if (!checkArguments(target.function, arguments, typeParameters)) { 1705 if (!checkArguments(target.function, arguments, typeParameters)) {
1705 return throwNoSuchMethodError(target.name.name, arguments, charOffset); 1706 return throwNoSuchMethodError(target.name.name, arguments, charOffset);
1706 } 1707 }
1707 if (target is Constructor) { 1708 if (target is Constructor) {
1708 return new ConstructorInvocation(target, arguments) 1709 return new ConstructorInvocation(target, arguments)
1709 ..isConst = isConst 1710 ..isConst = isConst
1710 ..fileOffset = charOffset; 1711 ..fileOffset = charOffset;
1711 } else { 1712 } else {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 } 1786 }
1786 1787
1787 String errorName; 1788 String errorName;
1788 if (type is ClassBuilder) { 1789 if (type is ClassBuilder) {
1789 Builder b = type.findConstructorOrFactory(name); 1790 Builder b = type.findConstructorOrFactory(name);
1790 Member target; 1791 Member target;
1791 if (b == null) { 1792 if (b == null) {
1792 // Not found. Reported below. 1793 // Not found. Reported below.
1793 } else if (b.isConstructor) { 1794 } else if (b.isConstructor) {
1794 if (type.isAbstract) { 1795 if (type.isAbstract) {
1795 // TODO(ahe): Generate abstract instantiation error. 1796 push(evaluateArgumentsBefore(
1797 arguments,
1798 buildAbstractClassInstantiationError(
1799 type.name, nameToken.charOffset)));
1800 return;
1796 } else { 1801 } else {
1797 target = b.target; 1802 target = b.target;
1798 } 1803 }
1799 } else if (b.isFactory) { 1804 } else if (b.isFactory) {
1800 target = getRedirectionTarget(b.target); 1805 target = getRedirectionTarget(b.target);
1801 if (target == null) { 1806 if (target == null) {
1802 push(buildCompileTimeError( 1807 push(buildCompileTimeError(
1803 "Cyclic definition of factory '${name}'.", 1808 "Cyclic definition of factory '${name}'.",
1804 nameToken.charOffset)); 1809 nameToken.charOffset));
1805 return; 1810 return;
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 } 2367 }
2363 return super.handleUnrecoverableError(token, kind, arguments); 2368 return super.handleUnrecoverableError(token, kind, arguments);
2364 } 2369 }
2365 2370
2366 @override 2371 @override
2367 Expression buildCompileTimeError(error, [int charOffset = -1]) { 2372 Expression buildCompileTimeError(error, [int charOffset = -1]) {
2368 addCompileTimeError(charOffset, error); 2373 addCompileTimeError(charOffset, error);
2369 String message = formatUnexpected(uri, charOffset, error); 2374 String message = formatUnexpected(uri, charOffset, error);
2370 Builder constructor = library.loader.getCompileTimeError(); 2375 Builder constructor = library.loader.getCompileTimeError();
2371 return new Throw(buildStaticInvocation(constructor.target, 2376 return new Throw(buildStaticInvocation(constructor.target,
2372 new Arguments(<Expression>[new StringLiteral(message)]), 2377 new Arguments(<Expression>[new StringLiteral(message)])));
2373 isConst: false)); // TODO(ahe): Make this const. 2378 }
2379
2380 Expression buildAbstractClassInstantiationError(String className,
2381 [int charOffset = -1]) {
2382 warning("The class '$className' is abstract and can't be instantiated.",
2383 charOffset);
2384 Builder constructor = library.loader.getAbstractClassInstantiationError();
2385 return new Throw(buildStaticInvocation(constructor.target,
2386 new Arguments(<Expression>[new StringLiteral(className)])));
2374 } 2387 }
2375 2388
2376 Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) { 2389 Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) {
2377 return new ExpressionStatement(buildCompileTimeError(error, charOffset)); 2390 return new ExpressionStatement(buildCompileTimeError(error, charOffset));
2378 } 2391 }
2379 2392
2380 @override 2393 @override
2381 Initializer buildCompileTimeErrorIntializer(error, [int charOffset = -1]) { 2394 Initializer buildCompileTimeErrorIntializer(error, [int charOffset = -1]) {
2382 return new LocalInitializer(new VariableDeclaration.forValue( 2395 return new LocalInitializer(new VariableDeclaration.forValue(
2383 buildCompileTimeError(error, charOffset))); 2396 buildCompileTimeError(error, charOffset)));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2417 2430
2418 @override 2431 @override
2419 void warning(String message, [int charOffset = -1]) { 2432 void warning(String message, [int charOffset = -1]) {
2420 if (constantExpressionRequired) { 2433 if (constantExpressionRequired) {
2421 addCompileTimeError(charOffset, message); 2434 addCompileTimeError(charOffset, message);
2422 } else { 2435 } else {
2423 super.warning(message, charOffset); 2436 super.warning(message, charOffset);
2424 } 2437 }
2425 } 2438 }
2426 2439
2440 Expression evaluateArgumentsBefore(
2441 Arguments arguments, Expression expression) {
2442 if (arguments == null) return expression;
2443 List<Expression> expressions =
2444 new List<Expression>.from(arguments.positional);
2445 for (NamedExpression named in arguments.named) {
2446 expressions.add(named.value);
2447 }
2448 for (Expression argument in expressions.reversed) {
2449 expression = new Let(
2450 new VariableDeclaration.forValue(argument, isFinal: true),
2451 expression);
2452 }
2453 return expression;
2454 }
2455
2427 @override 2456 @override
2428 void debugEvent(String name) { 2457 void debugEvent(String name) {
2429 // printEvent(name); 2458 // printEvent(name);
2430 } 2459 }
2431 } 2460 }
2432 2461
2433 // TODO(ahe): Shouldn't need to be an expression. 2462 // TODO(ahe): Shouldn't need to be an expression.
2434 class UnresolvedIdentifier extends InvalidExpression { 2463 class UnresolvedIdentifier extends InvalidExpression {
2435 final Name name; 2464 final Name name;
2436 2465
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
2897 } else if (node is PrefixBuilder) { 2926 } else if (node is PrefixBuilder) {
2898 return node.name; 2927 return node.name;
2899 } else if (node is ThisAccessor) { 2928 } else if (node is ThisAccessor) {
2900 return node.isSuper ? "super" : "this"; 2929 return node.isSuper ? "super" : "this";
2901 } else if (node is FastaAccessor) { 2930 } else if (node is FastaAccessor) {
2902 return node.plainNameForRead; 2931 return node.plainNameForRead;
2903 } else { 2932 } else {
2904 return internalError("Unhandled: ${node.runtimeType}"); 2933 return internalError("Unhandled: ${node.runtimeType}");
2905 } 2934 }
2906 } 2935 }
OLDNEW
« 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