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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/resolution/resolution.dart
diff --git a/pkg/compiler/lib/src/resolution/resolution.dart b/pkg/compiler/lib/src/resolution/resolution.dart
index 6c4f90b232c6adb126da9a4910fc1e7a5a8b5bb2..737b5f041b975c65c3818223fde6927985f0f4bd 100644
--- a/pkg/compiler/lib/src/resolution/resolution.dart
+++ b/pkg/compiler/lib/src/resolution/resolution.dart
@@ -21,6 +21,11 @@ import '../compiler.dart' show
Compiler;
import '../compile_time_constants.dart' show
ConstantCompiler;
+import '../constants/expressions.dart' show
+ ConstantExpression,
+ ConstantExpressionKind,
+ ConstructedConstantExpression,
+ ErroneousConstantExpression;
import '../constants/values.dart' show
ConstantValue;
import '../core_types.dart' show
@@ -1061,8 +1066,29 @@ class ResolverTask extends CompilerTask {
node.accept(visitor);
// TODO(johnniwinther): Avoid passing the [TreeElements] to
// [compileMetadata].
- annotation.constant =
- constantCompiler.compileMetadata(annotation, node, registry.mapping);
+ ConstantExpression constant = constantCompiler.compileMetadata(
+ annotation, node, registry.mapping);
+ switch (constant.kind) {
+ case ConstantExpressionKind.CONSTRUCTED:
+ ConstructedConstantExpression constructedConstant = constant;
+ if (constructedConstant.type.isGeneric) {
+ // Const constructor calls cannot have type arguments.
+ // TODO(24312): Remove this.
+ reporter.reportErrorMessage(
+ node, MessageKind.INVALID_METADATA_GENERIC);
+ constant = new ErroneousConstantExpression();
+ }
+ break;
+ case ConstantExpressionKind.VARIABLE:
+ case ConstantExpressionKind.ERRONEOUS:
+ break;
+ default:
+ reporter.reportErrorMessage(node, MessageKind.INVALID_METADATA);
+ constant = new ErroneousConstantExpression();
+ break;
+ }
+ annotation.constant = constant;
+
constantCompiler.evaluate(annotation.constant);
// TODO(johnniwinther): Register the relation between the annotation
// and the annotated element instead. This will allow the backend to
« 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