Closed pboyer closed 8 years ago
How was that causing the test failure?
On Oct 5, 2016, at 7:56 PM, Peter Boyer notifications@github.com wrote:
@pboyer commented on this pull request.
In runtime/Go/antlr/tree.go:
@@ -45,6 +45,8 @@ type TerminalNode interface {
type ErrorNode interface { TerminalNode +
- errorNode() Before this change, an ErrorNode and TerminalNode were indistinguishable.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@willfaught This test created a custom ParseTreeListener
. This data structure implemented a VisitTerminal
method that printed the node. The VisitErrorNode
method was empty.
Before this change, an ErrorNode
and TerminalNode
were type-wise identical. Note the implementation of the ErrorNode
interface. So, the VisitErrorNode
method was called (see the type switch) and the node was not printed. In Java, these would be distinguishable. Go's duck typing like semantics cause this issue.
A common approach to this problem is to have a method that distinguishes the interface. See for example: https://github.com/golang/go/blob/master/src/go/ast/ast.go#L491
This is the approach I took here.
I was interested more in where in the code the type confusion was causing the problem. In any case the change makes sense and LGTM!
Fix for #57
@willfaught PTAL