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

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

Issue 1161823004: Handle .fromEnvironment and incompatible constructor invocations (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Change handling of incompatible redirecting factories. 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 5910234a3252c6f13811bf11d901444710070896..64d62ddb83f2fcc44eee0a872ee5348f3302d1b8 100644
--- a/pkg/compiler/lib/src/resolution/send_resolver.dart
+++ b/pkg/compiler/lib/src/resolution/send_resolver.dart
@@ -541,6 +541,7 @@ abstract class SendResolverMixin {
ConstructorAccessSemantics computeConstructorAccessSemantics(
ConstructorElement constructor,
+ CallStructure callStructure,
DartType type,
{bool mustBeConstant: false}) {
if (mustBeConstant && !constructor.isConst) {
@@ -570,6 +571,7 @@ abstract class SendResolverMixin {
ConstructorAccessSemantics effectiveTargetSemantics =
computeConstructorAccessSemantics(
effectiveTarget,
+ callStructure,
constructor.computeEffectiveTargetType(type));
if (effectiveTargetSemantics.isErroneous) {
return new RedirectingFactoryConstructorAccessSemantics(
@@ -583,22 +585,29 @@ abstract class SendResolverMixin {
constructor,
type,
effectiveTargetSemantics);
- } else if (constructor.isFactoryConstructor) {
- return new ConstructorAccessSemantics(
- ConstructorAccessKind.FACTORY, constructor, type);
- } else if (constructor.isRedirectingGenerative) {
- if (constructor.enclosingClass.isAbstract) {
- return new ConstructorAccessSemantics(
- ConstructorAccessKind.ABSTRACT, constructor, type);
- }
- return new ConstructorAccessSemantics(
- ConstructorAccessKind.REDIRECTING_GENERATIVE, constructor, type);
- } else if (constructor.enclosingClass.isAbstract) {
- return new ConstructorAccessSemantics(
- ConstructorAccessKind.ABSTRACT, constructor, type);
} else {
- return new ConstructorAccessSemantics(
- ConstructorAccessKind.GENERATIVE, constructor, type);
+ if (!callStructure.signatureApplies(constructor)) {
+ return new ConstructorAccessSemantics(
+ ConstructorAccessKind.INCOMPATIBLE,
+ constructor,
+ type);
+ } else if (constructor.isFactoryConstructor) {
+ return new ConstructorAccessSemantics(
+ ConstructorAccessKind.FACTORY, constructor, type);
+ } else if (constructor.isRedirectingGenerative) {
+ if (constructor.enclosingClass.isAbstract) {
+ return new ConstructorAccessSemantics(
+ ConstructorAccessKind.ABSTRACT, constructor, type);
+ }
+ return new ConstructorAccessSemantics(
+ ConstructorAccessKind.REDIRECTING_GENERATIVE, constructor, type);
+ } else if (constructor.enclosingClass.isAbstract) {
+ return new ConstructorAccessSemantics(
+ ConstructorAccessKind.ABSTRACT, constructor, type);
+ } else {
+ return new ConstructorAccessSemantics(
+ ConstructorAccessKind.GENERATIVE, constructor, type);
+ }
}
}
@@ -609,17 +618,37 @@ abstract class SendResolverMixin {
ConstructorAccessSemantics constructorAccessSemantics =
computeConstructorAccessSemantics(
- element, type, mustBeConstant: node.isConst);
+ element, selector.callStructure, type,
+ mustBeConstant: node.isConst);
if (node.isConst) {
ConstantExpression constant = elements.getConstant(node);
if (constructorAccessSemantics.isErroneous ||
- constant is! ConstructedConstantExpression) {
+ constant == null ||
+ constant.kind == ConstantExpressionKind.ERRONEOUS) {
// 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);
+ ConstantInvokeKind kind;
+ switch (constant.kind) {
+ case ConstantExpressionKind.CONSTRUCTED:
+ kind = ConstantInvokeKind.CONSTRUCTED;
+ break;
+ case ConstantExpressionKind.BOOL_FROM_ENVIRONMENT:
+ kind = ConstantInvokeKind.BOOL_FROM_ENVIRONMENT;
+ break;
+ case ConstantExpressionKind.INT_FROM_ENVIRONMENT:
+ kind = ConstantInvokeKind.INT_FROM_ENVIRONMENT;
+ break;
+ case ConstantExpressionKind.STRING_FROM_ENVIRONMENT:
+ kind = ConstantInvokeKind.STRING_FROM_ENVIRONMENT;
+ break;
+ default:
+ return internalError(
+ node, "Unexpected constant kind $kind: ${constant.getText()}");
+ }
+ return new ConstInvokeStructure(kind, constant);
}
}
return new NewInvokeStructure(constructorAccessSemantics, selector);
« no previous file with comments | « pkg/compiler/lib/src/resolution/semantic_visitor_mixins.dart ('k') | pkg/compiler/lib/src/resolution/send_structure.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698