-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure AST nodes have correct locations #13453
Comments
I think it shouldn't be difficult to build a visitor that traverses the entire tree and checks all nodes' locations. That's at least for validating presence. Correctness is a different story. But I suppose when there's a location, it should be reasonably correct. Some sanity check could also cover that child nodes are enclosed between location and end location. Should be a fun excercise for anyone who would like to get acquainted with the compiler's visitor pattern 😏 |
😳 I actually have a branch that checks node locations for each test string in class LocationVisitor < Crystal::Visitor
def initialize(*, @file : String, @line : Int32)
end
def visit(node)
return false unless check_node?(node)
node.location.should_not be_nil, file: @file, line: @line, failure_message: "Unexpected nil location of #{node.class_desc} #{node.to_s.inspect}"
node.end_location.should_not be_nil, file: @file, line: @line, failure_message: "Unexpected nil end_location of #{node.class_desc} #{node.to_s.inspect}"
return false unless check_children?(node)
true
end
private def check_node?(node)
# ...
end
private def check_children?(node)
# ...
end
end
|
I noticed that named tuple keys are lacking a location, meaning it's not currently possible (as far as I can tell) to have a compile time error in a macro pointing at a specific key. Probably because the keys are read as strings without any location info. |
Originally posted by @oprypin in #13452 (comment)
Do you think it's possible to make a generated test suite that asserts that all nodes have correct locations?
The text was updated successfully, but these errors were encountered: