Skip to content

Commit 8c4c0f8

Browse files
authored
Make accept a generic method (#21)
Stop throwing away types from the `Visitor` which already has a generic. Use generic for RecursiveVisitor instead of allowing an implicit `dynamic`.
1 parent 55301c0 commit 8c4c0f8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/src/ast.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class Node {
2121
Iterable<String> get variables;
2222

2323
/// Calls the appropriate [Visitor] method on [this] and returns the result.
24-
dynamic accept(Visitor visitor);
24+
T accept<T>(Visitor<T> visitor);
2525
}
2626

2727
/// A single variable.
@@ -38,7 +38,7 @@ class VariableNode implements Node {
3838
VariableNode(this.name, [this.span]);
3939

4040
@override
41-
dynamic accept(Visitor visitor) => visitor.visitVariable(this);
41+
T accept<T>(Visitor<T> visitor) => visitor.visitVariable(this);
4242

4343
@override
4444
String toString() => name;
@@ -64,7 +64,7 @@ class NotNode implements Node {
6464
NotNode(this.child, [this.span]);
6565

6666
@override
67-
dynamic accept(Visitor visitor) => visitor.visitNot(this);
67+
T accept<T>(Visitor<T> visitor) => visitor.visitNot(this);
6868

6969
@override
7070
String toString() =>
@@ -97,7 +97,7 @@ class OrNode implements Node {
9797
OrNode(this.left, this.right);
9898

9999
@override
100-
dynamic accept(Visitor visitor) => visitor.visitOr(this);
100+
T accept<T>(Visitor<T> visitor) => visitor.visitOr(this);
101101

102102
@override
103103
String toString() {
@@ -136,7 +136,7 @@ class AndNode implements Node {
136136
AndNode(this.left, this.right);
137137

138138
@override
139-
dynamic accept(Visitor visitor) => visitor.visitAnd(this);
139+
T accept<T>(Visitor<T> visitor) => visitor.visitAnd(this);
140140

141141
@override
142142
String toString() {
@@ -179,7 +179,7 @@ class ConditionalNode implements Node {
179179
ConditionalNode(this.condition, this.whenTrue, this.whenFalse);
180180

181181
@override
182-
dynamic accept(Visitor visitor) => visitor.visitConditional(this);
182+
T accept<T>(Visitor<T> visitor) => visitor.visitConditional(this);
183183

184184
@override
185185
String toString() {

lib/src/visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class Visitor<T> {
1717
///
1818
/// The default implementations of this visitor's methods just traverse the AST
1919
/// and do nothing with it.
20-
abstract class RecursiveVisitor implements Visitor {
20+
abstract class RecursiveVisitor implements Visitor<void> {
2121
const RecursiveVisitor();
2222

2323
@override

0 commit comments

Comments
 (0)