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

Side by Side Diff: pkg/compiler/lib/src/resolution/resolution.dart

Issue 1510863004: Report compile-time error on disallowed metadata values. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.resolution; 5 library dart2js.resolution;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart' show 10 import '../common/names.dart' show
11 Identifiers; 11 Identifiers;
12 import '../common/resolution.dart' show 12 import '../common/resolution.dart' show
13 Feature, 13 Feature,
14 Parsing, 14 Parsing,
15 Resolution, 15 Resolution,
16 ResolutionImpact; 16 ResolutionImpact;
17 import '../common/tasks.dart' show 17 import '../common/tasks.dart' show
18 CompilerTask, 18 CompilerTask,
19 DeferredAction; 19 DeferredAction;
20 import '../compiler.dart' show 20 import '../compiler.dart' show
21 Compiler; 21 Compiler;
22 import '../compile_time_constants.dart' show 22 import '../compile_time_constants.dart' show
23 ConstantCompiler; 23 ConstantCompiler;
24 import '../constants/expressions.dart' show
25 ConstantExpression,
26 ConstantExpressionKind,
27 ConstructedConstantExpression,
28 ErroneousConstantExpression;
24 import '../constants/values.dart' show 29 import '../constants/values.dart' show
25 ConstantValue; 30 ConstantValue;
26 import '../core_types.dart' show 31 import '../core_types.dart' show
27 CoreClasses, 32 CoreClasses,
28 CoreTypes; 33 CoreTypes;
29 import '../dart_types.dart'; 34 import '../dart_types.dart';
30 import '../elements/elements.dart'; 35 import '../elements/elements.dart';
31 import '../elements/modelx.dart' show 36 import '../elements/modelx.dart' show
32 BaseClassElementX, 37 BaseClassElementX,
33 BaseFunctionElementX, 38 BaseFunctionElementX,
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 classElement.ensureResolved(resolution); 1059 classElement.ensureResolved(resolution);
1055 } 1060 }
1056 assert(invariant(node, context != null, 1061 assert(invariant(node, context != null,
1057 message: "No context found for metadata annotation " 1062 message: "No context found for metadata annotation "
1058 "on $annotatedElement.")); 1063 "on $annotatedElement."));
1059 ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true); 1064 ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true);
1060 ResolutionRegistry registry = visitor.registry; 1065 ResolutionRegistry registry = visitor.registry;
1061 node.accept(visitor); 1066 node.accept(visitor);
1062 // TODO(johnniwinther): Avoid passing the [TreeElements] to 1067 // TODO(johnniwinther): Avoid passing the [TreeElements] to
1063 // [compileMetadata]. 1068 // [compileMetadata].
1064 annotation.constant = 1069 ConstantExpression constant = constantCompiler.compileMetadata(
1065 constantCompiler.compileMetadata(annotation, node, registry.mapping); 1070 annotation, node, registry.mapping);
1071 switch (constant.kind) {
1072 case ConstantExpressionKind.CONSTRUCTED:
1073 ConstructedConstantExpression constructedConstant = constant;
1074 if (constructedConstant.type.isGeneric) {
1075 // Const constructor calls cannot have type arguments.
1076 // TODO(24312): Remove this.
1077 reporter.reportErrorMessage(
1078 node, MessageKind.INVALID_METADATA_GENERIC);
1079 constant = new ErroneousConstantExpression();
1080 }
1081 break;
1082 case ConstantExpressionKind.VARIABLE:
1083 case ConstantExpressionKind.ERRONEOUS:
1084 break;
1085 default:
1086 reporter.reportErrorMessage(node, MessageKind.INVALID_METADATA);
1087 constant = new ErroneousConstantExpression();
1088 break;
1089 }
1090 annotation.constant = constant;
1091
1066 constantCompiler.evaluate(annotation.constant); 1092 constantCompiler.evaluate(annotation.constant);
1067 // TODO(johnniwinther): Register the relation between the annotation 1093 // TODO(johnniwinther): Register the relation between the annotation
1068 // and the annotated element instead. This will allow the backend to 1094 // and the annotated element instead. This will allow the backend to
1069 // retrieve the backend constant and only register metadata on the 1095 // retrieve the backend constant and only register metadata on the
1070 // elements for which it is needed. (Issue 17732). 1096 // elements for which it is needed. (Issue 17732).
1071 registry.registerMetadataConstant(annotation); 1097 registry.registerMetadataConstant(annotation);
1072 annotation.resolutionState = STATE_DONE; 1098 annotation.resolutionState = STATE_DONE;
1073 })); 1099 }));
1074 } 1100 }
1075 1101
(...skipping 25 matching lines...) Expand all
1101 TreeElements get treeElements { 1127 TreeElements get treeElements {
1102 assert(invariant(this, _treeElements !=null, 1128 assert(invariant(this, _treeElements !=null,
1103 message: "TreeElements have not been computed for $this.")); 1129 message: "TreeElements have not been computed for $this."));
1104 return _treeElements; 1130 return _treeElements;
1105 } 1131 }
1106 1132
1107 void reuseElement() { 1133 void reuseElement() {
1108 _treeElements = null; 1134 _treeElements = null;
1109 } 1135 }
1110 } 1136 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/diagnostics/messages.dart ('k') | tests/compiler/dart2js/mirrors_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698