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

Unified Diff: pkg/compiler/lib/src/resolution/send_resolver.dart

Issue 1140903002: Handle constant constructors with parse errors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 5 years, 7 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
Index: pkg/compiler/lib/src/resolution/send_resolver.dart
diff --git a/pkg/compiler/lib/src/resolution/send_resolver.dart b/pkg/compiler/lib/src/resolution/send_resolver.dart
index f4bbaa5339cb96e14a9ca85271192efd46cfbc79..22cf9bc04bea2cf172d8ac20c1e78ba1bf97325c 100644
--- a/pkg/compiler/lib/src/resolution/send_resolver.dart
+++ b/pkg/compiler/lib/src/resolution/send_resolver.dart
@@ -430,7 +430,12 @@ abstract class SendResolverMixin {
ConstructorAccessSemantics computeConstructorAccessSemantics(
ConstructorElement constructor,
- DartType type) {
+ DartType type,
+ {bool mustBeConstant: false}) {
+ if (mustBeConstant && !constructor.isConst) {
+ return new ConstructorAccessSemantics(
+ ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR, constructor, type);
+ }
if (constructor.isErroneous) {
if (constructor is ErroneousElement) {
ErroneousElement error = constructor;
@@ -444,7 +449,8 @@ abstract class SendResolverMixin {
} else if (constructor.isRedirectingFactory) {
ConstructorElement effectiveTarget = constructor.effectiveTarget;
if (effectiveTarget == constructor ||
- effectiveTarget.isErroneous) {
+ effectiveTarget.isErroneous ||
+ (mustBeConstant && !effectiveTarget.isConst)) {
return new ConstructorAccessSemantics(
ConstructorAccessKind.ERRONEOUS_REDIRECTING_FACTORY,
constructor,
@@ -486,26 +492,24 @@ abstract class SendResolverMixin {
}
NewStructure computeNewStructure(NewExpression node) {
- if (node.isConst) {
- ConstantExpression constant = elements.getConstant(node);
- if (constant is ConstructedConstantExpression) {
- return new ConstInvokeStructure(constant);
- }
- }
-
Element element = elements[node.send];
Selector selector = elements.getSelector(node.send);
DartType type = elements.getType(node);
- ConstructorAccessSemantics constructorAccessSemantics;
+ ConstructorAccessSemantics constructorAccessSemantics =
+ computeConstructorAccessSemantics(
+ element, type, mustBeConstant: node.isConst);
if (node.isConst) {
- // This is a non-constant constant constructor invocation, like
- // `const Const(method())`.
- constructorAccessSemantics = new ConstructorAccessSemantics(
- ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR, element, type);
- } else {
- constructorAccessSemantics =
- computeConstructorAccessSemantics(element, type);
+ ConstantExpression constant = elements.getConstant(node);
+ if (constructorAccessSemantics.isErroneous ||
+ constant is! ConstructedConstantExpression) {
+ // This is a non-constant constant constructor invocation, like
+ // `const Const(method())`.
+ constructorAccessSemantics = new ConstructorAccessSemantics(
+ ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR, element, type);
+ } else {
+ return new ConstInvokeStructure(constant);
+ }
}
return new NewInvokeStructure(constructorAccessSemantics, selector);
}
« no previous file with comments | « pkg/compiler/lib/src/resolution/semantic_visitor_mixins.dart ('k') | tests/compiler/dart2js/semantic_visitor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698