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

Unified Diff: pkg/kernel/lib/verifier.dart

Issue 2539743002: Add more checks to kernel verifier. (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | pkg/kernel/test/verify_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/verifier.dart
diff --git a/pkg/kernel/lib/verifier.dart b/pkg/kernel/lib/verifier.dart
index 27cc492260ae32ead00e22b3e067b2030556802f..e40b2c00ca0729eaffb100c384ed4599c95a2b41 100644
--- a/pkg/kernel/lib/verifier.dart
+++ b/pkg/kernel/lib/verifier.dart
@@ -92,6 +92,19 @@ class VerifyingVisitor extends RecursiveVisitor {
variable.flags &= ~VariableDeclaration.FlagInScope;
}
+ void declareTypeParameters(List<TypeParameter> parameters) {
+ for (int i = 0; i < parameters.length; ++i) {
+ var parameter = parameters[i];
+ if (!typeParameters.add(parameter)) {
+ throw 'Type parameter $parameter redeclared in $context';
+ }
+ }
+ }
+
+ void undeclareTypeParameters(List<TypeParameter> parameters) {
+ typeParameters.removeAll(parameters);
+ }
+
void checkVariableInScope(VariableDeclaration variable, TreeNode where) {
if (variable.flags & VariableDeclaration.FlagInScope == 0) {
throw 'Variable $variable used out of scope in $context '
@@ -101,7 +114,11 @@ class VerifyingVisitor extends RecursiveVisitor {
visitProgram(Program program) {
for (var library in program.libraries) {
- classes.addAll(library.classes);
+ for (var class_ in library.classes) {
+ if (!classes.add(class_)) {
+ throw 'Class $class_ declared more than once';
+ }
+ }
library.members.forEach(declareMember);
for (var class_ in library.classes) {
class_.members.forEach(declareMember);
@@ -157,7 +174,7 @@ class VerifyingVisitor extends RecursiveVisitor {
visitClass(Class node) {
currentClass = node;
- typeParameters.addAll(node.typeParameters);
+ declareTypeParameters(node.typeParameters);
var oldParent = enterParent(node);
classTypeParametersAreInScope = false;
visitList(node.annotations, this);
@@ -167,14 +184,14 @@ class VerifyingVisitor extends RecursiveVisitor {
visitList(node.constructors, this);
visitList(node.procedures, this);
exitParent(oldParent);
- typeParameters.removeAll(node.typeParameters);
+ undeclareTypeParameters(node.typeParameters);
currentClass = null;
}
visitFunctionNode(FunctionNode node) {
- typeParameters.addAll(node.typeParameters);
+ declareTypeParameters(node.typeParameters);
visitWithLocalScope(node);
- typeParameters.removeAll(node.typeParameters);
+ undeclareTypeParameters(node.typeParameters);
}
visitFunctionType(FunctionType node) {
@@ -184,14 +201,14 @@ class VerifyingVisitor extends RecursiveVisitor {
'$context';
}
}
- typeParameters.addAll(node.typeParameters);
+ declareTypeParameters(node.typeParameters);
for (var typeParameter in node.typeParameters) {
typeParameter.bound?.accept(this);
}
visitList(node.positionalParameters, this);
visitList(node.namedParameters, this);
node.returnType.accept(this);
- typeParameters.removeAll(node.typeParameters);
+ undeclareTypeParameters(node.typeParameters);
}
visitBlock(Block node) {
« no previous file with comments | « no previous file | pkg/kernel/test/verify_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698