ruby / prism

Prism Ruby parser
https://ruby.github.io/prism/
MIT License
790 stars 134 forks source link

ConstantReadNode in ClassNode#constant_path or ModuleNode#constant_path is not just a constant read #2876

Closed tompng closed 1 week ago

tompng commented 1 month ago

For class A; end, ClassNode#constant_path is ConstantReadNode but it is different from normal constant read.

module M
  p Array # ConstantReadNode, reads Object::Array
  class Array # ConstantReadNode, but does not read Object::Array.
  end
  p Array # M::Array
  class Array # ConstantReadNode, reads M::Array.
  end
end

Perhaps renaming ConstantReadNode to ConstantNode might be consistent? Just like ConstantPathNode is read (x=A::B) or write target (A::B=x) depend on where the node appears.

ConstantPath related constant is named:
/Prism::ConstantPath(Target|(Operator|And|Or)?Write)?Node/

Renaming ConstantReadNode to ConstantNode, names will be:
/Prism::Constant(Target|(Operator|And|Or)?Write)?Node/

I'm not having problem, reported just in case.

kddnewton commented 1 week ago

Hey @tompng — I definitely get what you're saying here. I've been thinking about it since you reported it, but I think I'm going to keep it as it is for now. A lot of people are depending on the API now, and adding this would be a big enough amount of churn that it would have to be fully worth it, and I think this is marginally worth it, but not enough. Thank you for understanding!